Re: [Resin-interest] Hibernate transactions

2010-03-30 Thread Wesley Wu
More to mention about MDBs (Message Driven Beans): 1. Always use @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) on public void onMessage(Message message). because the impl of Resin MDBs has severe reenter synchronization problem. If I start a transaction before onMessage() being cal

Re: [Resin-interest] Hibernate transactions

2010-03-30 Thread Wesley Wu
I will not call UserTransaction.begin() when all db operations are SELECT. I create a EntityManager from emf to do SELECT stuff with no transaction at all. When I detected there're some update/delete operations, I'll do this: 1. close the former created EntityManager if there is one (for precedent

Re: [Resin-interest] Hibernate transactions

2010-03-30 Thread Stargazer
On 30-Mar-2010 18:03, Scott Ferguson wrote: > Wesley Wu wrote: > >> Yes. One minor problem: >> >> @PersistentContext should be @PersistentUnit. >> > would calling UserTransaction in your code be faster? Essentially, > I don't know about the finer details, but looking back on this

Re: [Resin-interest] Hibernate transactions

2010-03-30 Thread Stargazer
On 30-Mar-2010 17:54, Wesley Wu wrote: > Yes. One minor problem: > > @PersistentContext should be @PersistentUnit. > Doh! Great, works now. Thanks for your help! ___ resin-interest mailing list resin-interest@caucho.com http://maillist.caucho.com/mail

Re: [Resin-interest] Hibernate transactions

2010-03-30 Thread Scott Ferguson
Wesley Wu wrote: > Yes. One minor problem: > > @PersistentContext should be @PersistentUnit. > > > That's exactly what I used to do in the past three years. > > I controlled the entitymanager and transaction by my own code in a JPA > wrapper class, > and gained great performance advantage over aut

Re: [Resin-interest] Hibernate transactions

2010-03-30 Thread Wesley Wu
Yes. One minor problem: @PersistentContext should be @PersistentUnit. That's exactly what I used to do in the past three years. I controlled the entitymanager and transaction by my own code in a JPA wrapper class, and gained great performance advantage over automatic transaction handling like @

Re: [Resin-interest] Hibernate transactions

2010-03-30 Thread Stargazer
On 30-Mar-2010 09:34, Wesley Wu wrote: > To make set method auto translated into a UPDATE clause, the > entitymanager should be opened after a transaction begins. > > Sincere thanks again, hopefully this will all help others coming across it in the future. If I understood you correctly I made

Re: [Resin-interest] Hibernate transactions

2010-03-30 Thread Wesley Wu
To make set method auto translated into a UPDATE clause, the entitymanager should be opened after a transaction begins. @PersistenceUnit(unitName="example") EntityManagerFactory emf; EntityManager em; try { ut.begin(); EntityManager em= emf.createEntityManager(); CourseBean u

Re: [Resin-interest] Hibernate transactions

2010-03-30 Thread Stargazer
On 30-Mar-2010 06:42, Wesley Wu wrote: > try { > ut.begin(); > CourseBean updateCourse = _manager.find(CourseBean.class, new > Integer(1)); > updateCourse.setCourse("Magic"); > ut.commit(); > } catch (Exception e) { > e.printStackTrace(); >

Re: [Resin-interest] Hibernate transactions

2010-03-29 Thread Wesley Wu
try { ut.begin(); CourseBean updateCourse = _manager.find(CourseBean.class, new Integer(1)); updateCourse.setCourse("Magic"); ut.commit(); } catch (Exception e) { e.printStackTrace(); } will work. -Wesley __

Re: [Resin-interest] Hibernate transactions

2010-03-29 Thread Stargazer
On 29-Mar-2010 17:48, Scott Ferguson wrote: Wesley Wu wrote: Not a version issue. An entitymanager should not get transaction by itself. Transaction in a modern java appserver should be XA or JTA transaciton. An entitymanager will detect if there is a JTA transaction existing and will join

Re: [Resin-interest] Hibernate transactions

2010-03-29 Thread Scott Ferguson
Wesley Wu wrote: > Not a version issue. > > An entitymanager should not get transaction by itself. Transaction in > a modern java appserver should be XA or JTA transaciton. > An entitymanager will detect if there is a JTA transaction existing > and will join it if there is an open one. > > You need

Re: [Resin-interest] Hibernate transactions

2010-03-29 Thread Wesley Wu
Not a version issue. An entitymanager should not get transaction by itself. Transaction in a modern java appserver should be XA or JTA transaciton. An entitymanager will detect if there is a JTA transaction existing and will join it if there is an open one. You need to use an injected UserTransac

Re: [Resin-interest] Hibernate transactions

2010-03-29 Thread Stargazer
On 27-Mar-2010 01:10, Stargazer wrote: > Resin 4.0.5 - following http://wiki.caucho.com/Hibernate works fine, but > I'd like to take it to the next level and persist something. > Adding > EntityTransaction tx = _manager.getTransaction(); > tx.begin(); > ... > to the en

Re: [Resin-interest] Hibernate transactions

2010-03-26 Thread Rick Mann
Also, the link at the very bottom of that page gets a 500 error: http://www.caucho.com/resin/examples/amber-basic/index.xtp > 500 Servlet Exception > > 'ejb3_basic_courses' is not a valid database table. Either the table needs > to be created or the create-database-tables attribute must be set.

[Resin-interest] Hibernate transactions

2010-03-26 Thread Stargazer
Resin 4.0.5 - following http://wiki.caucho.com/Hibernate works fine, but I'd like to take it to the next level and persist something. Adding EntityTransaction tx = _manager.getTransaction(); tx.begin(); ... to the end of the CourseServlet.java file throws up java.lang.I