×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

这里是我的所谓"正解“。欢迎讨论.俺已将此解用于美加公司五年。Oracle + WebSphere (or WebLogic). No Spring, no SEAM. J2EE containers are responsible for getting DB connection, transaction management, Hibernate session flush / close.

<hibernate-configuration>
<session-factory name="hibernate/SessionFactory_MyDataSrcX">
<property name="connection.datasource">java:comp/env/jdbc/MyDataSrcX</property>
<property name="dialect">org.hibernate.dialect.oracledialect</property>
<property name="show_sql">false</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WebSphereExtendedJTATransactionLookup</property>
<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.connection.release_mode">auto</property>
<property name="hibernate.transaction.auto_close_session">true</property>

... ...
Sign in and Reply Report

Replies, comments and Discussions:

  • 工作学习 / 事业与工作 / 午饭被吃掉的弟兄(java中年失业男)面试失败有感
    数日前, who8mylunch(java中年失业男)“不幸”面试失败。其实,失败乃兵家常事。兵书亦云,失败乃成功之母。不要泄气。A puzzle for a job interview is that, you NEVER know what should you perform in the interview.Reasoning:

    a. In the case, he was only interviewing for an intermediate position. In my theory, TA 不能表现得太好,否则面试你的人没有安全感。当然,太差的话人家不要你。

    b. 就考试而言,我通常只取那些考分在 60-85%的 candidates.低于60,可能干活不行。高于85,可能最近读了不少书。极有可能是个纸上谈兵派。当然,也可能是个超级高手。想想,我们有多少次招超级高手呢?超级高手的想法很可能跟你不一样,虽然很可能是个好主意。
    • 太精辟了。谢谢。
      • 还差一句更重要的. 向他们推荐"牛哥web app dev framework", 一则你对他们没有任何威胁, 二, 对他们而言也是个学习的契机. 全新理念, 中国人就是行! 你们东欧的,除了推倒一堵墙,杀了一个总统, 还推出啥了?
    • uhm?有道理。顺便说说,我们的project里,只有Senior做哪些Hibernate mapping. 大伙儿说说,你们哪儿也是这样操作的吗?
      • Hibernate里面option太多,牵涉到performance,很多需要Sr programmer和DBA 一起决定。
        • File structure, entity (object) relationship, connection / session / transaction management all decided by the architect. An intermediate developer can add a new column to the mapping (hehe, 照葫芦画瓢的那种)。
        • For the N-tier web app running in an app server, lazy loading is useless. And by default, we always set it to false.
          • i don't understand this. there is lazy setting both in JPA and hibernate. They are useless if it is a n-tier web app? are you sure?
      • Java is totally crap. Move to .NET
        • Yes, the technologies in the Java horizon are now a little complicated. but they are also powerful. .NET is "too simple, sometimes naive". Believe or not, most enterprise computings rely upon Java ( and C++ which is more complicated than Java).
          • It's not complicated, it's crappy
            • I have to disagree.
              Java is about choice, vendor independence ( or excellent portability to other vendor, to be accurate), excellent enterprise integration capabilities.
            • Mind to tell us more specific how and what .Net is crappy!
        • 今天还接了个Florida中介的电话要找从Java转平台到.net的...难道真的?
          • Well, this cannot be translated to "Java is totally crap". In terms of cost, .NET is way cheaper - for contracting in Canada, it's around $50-65/hr vs Java $60-80/hr. Blame the recession, rather than the technologies.
          • Java shop is Costco, .net is Wal-Mart.
            • :)
        • why? What .Net is better than Java?
          • Core Java is good, jdbc, jsp are ok. EJB, Hiberate, Structs, Spring are all crap.
        • 数据库的东西和.Net Java的区别没有关系。
    • 拿到面试机会的,基本都能干活。最终成败看细节,熟练程度也在细节上。
    • 我幽幽地低声问一句,sessionFactory.getCurrentSession(),真的没有人用过吗?
      • 这里是我的所谓"正解“。欢迎讨论.俺已将此解用于美加公司五年。Oracle + WebSphere (or WebLogic). No Spring, no SEAM. J2EE containers are responsible for getting DB connection, transaction management, Hibernate session flush / close.
        <hibernate-configuration>
        <session-factory name="hibernate/SessionFactory_MyDataSrcX">
        <property name="connection.datasource">java:comp/env/jdbc/MyDataSrcX</property>
        <property name="dialect">org.hibernate.dialect.oracledialect</property>
        <property name="show_sql">false</property>
        <property name="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
        <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WebSphereExtendedJTATransactionLookup</property>
        <property name="hibernate.transaction.flush_before_completion">true</property>
        <property name="hibernate.connection.release_mode">auto</property>
        <property name="hibernate.transaction.auto_close_session">true</property>

        ... ...
        • This is what's in Hibernate text book.
          Session sess = factory.openSession();
          Transaction tx;
          try {
          tx = sess.beginTransaction();
          //do some work
          ...
          tx.commit();
          }
          catch (Exception e) {
          if (tx!=null) tx.rollback();
          throw e;
          }
          finally {
          sess.close();
          }
        • And this is my design . tx.beginTX() / .commit() / .rollback(); sess.close() are never used in my code. They are all handled by WebSphere / WebLogic. My Hibernate never interacts with HTTP Session.
          Session sess = getSession(); // a single DB TX can span multiple getSession() calls

          //do some work;

          // NO tx.beginTX() / .commit() / .rollback(); nor sess.close() in the code.

          ...

          //end
          • If you rely on the container, how can you tell the container does not associate hibernate session to http session in some cases? In reality, EJBe containers all support extended persistent context (see JPA), which is the same concept.
            • transaction should be managed by some container, like EJB contiainer or sping, you also can handle transaction in your code,like trans.commit(), trans.rollback();....
            • use @TransactionAttribute(TransactionAttributeType.NEVER)
      • 正确答案在这里。
        • 绑定your Hibernate Session in your HttpSession 应该是不好的,
          以下内容转帖自http://www.redhat.com/docs/en-US/JBoss_Enterprise_Application_Platform/4.2.0.cp07/html/Hibernate_Reference_Guide/Transactions_And_Concurrency.html

          If you keep your Hibernate Session in your HttpSession (discussed later), you should consider synchronizing access to your Http session. Otherwise, a user that clicks reload fast enough may use the same Session in two concurrently running threads.
          • 在现在Ajax calle漫山遍野的情况下,有谁不synchronize httpsession?你觉得synchronize httpsession是不正常情况?
            • 什么是synchronize httpsession?
        • CherryHill 高手
          你能比较一下用JTA 和 THREADLOCAL 管理 HIBERNATE SESSION各有什么优劣吗?

          谢谢。
          • JTA只是一个标准,各家有各家自己的实现,比如WebLogic,WebSphere,JBoss之类的application server, 还有JBossTS和Atomikos之类的standalone的transaction manager。
            JTA和ThreadLocal绑定应该是等价的,JTA是application server环境下的默认,ThreadLocal绑定只不过是提供一个没有application server环境下的绑定手段而已。
    • 只要能进去,就说明你行。所以,聪明写简历,聪明应面试。如果进去被layoff,就是关系没有搞好.. rule I: dont be aggressive rule 2 be a productive team member rule3 follow supervisor instructions
    • 难怪我以前一考试就歇菜,原来是武大郎开店搞得
    • Can I ask a very simple question? I have not done web development / Java more than 6 years. So I like to know why we should use persistent objects / hibernate?
      • because plain JDBC looks dumb, dude.
        • If it doesn't take too much time, can you please give me an exmaple the benefits of persistent object / hibernate?
          • By representing data in objects, you got the flexibility of handling the data in the object oriented way (presumably advantageous from the software development perspective). Otherwise
            You have to embed SQL scripts in your code to handle data manipulation logic -- which are consider "eye sore" by many developers; or to call stored procedures-- which is harder to refactor.

            The above is just my understanding -- there could be more.

            That said -- nowadays, frenquently the business has the say in software development, and they typically just want the currently prescribed functionality deliver fast and cheap. Long term maitenanability,etc, is simply not a business concern.
            • Thanks a lot. But does EJB already encapsulate the data / SQL scripts inside? What does this persistant object offer on top on EJB?
              Your observation is very true, in the industry that I used to work, they have a lot of super users who did a lot of programming themselves. Anyone know "if...then....else" can do programming but a good developer must understand much more than just programming.

              And this is part of what my small business do. Providing training, couch on how they should have a proper design pattern, a well defined development proceesses.... etc. I am not a good marketing guy and all I do is to publish articles on their professional magazine and conduct presentation at their seminars.

              Do you mind to tell me more about business users computing in your organization? I hope I can develop a business relationship and provide my consulting servcies to your company.
              • JPA (Java Persistence API) is part of EJB 3, while Hibernate is one implementation of JPA. Also, Hibernate can be used without EJB.
            • you may get performance problem too.
    • I'm always curious why each time my agent told me my score is very high, and I didn't even get interviews!
      • What did you put on your resume? Not just put down your job description, i.e. what did you do. You have to put down your achievement! Job description is feaute and achievement is benefit. What benefits you are going to bring to my company?
      • Now you know 江湖的险恶。万事讲究一个度,这点老马和老毛都承认。呵呵,量变引起质变吗。
    • 继续努力,JAVA机会多的很。 很多大公司要求考试都是很严的,上次有个大银行ONLINE考试STD,超级难,我只拿了60分,那个人打电话跟我说必须要80分以上,估计能考到这分数的不是刚读过书的就是超级高手。
      • 不是“刚读过书的”,而是“刚查阅过原版英文资料的”。有时候换个说法,语气都大不一样。