-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Hibernate EntityManager, Annotations, CMT and transactions
PostPosted: Tue Nov 29, 2005 10:12 am 
Newbie

Joined: Thu Nov 24, 2005 8:48 am
Posts: 10
Hello,

I am very new to Hibernate so my question might be stupid but I cannot find any resource that could help me solve my problem.

I have application (first few lines) in CMT environment on Tomcat (using JOTM). I use EntityManager and Annotations. I am trying to figure out how to demarcate transactions using annotations. Hibernate EntityManager documentation says:

Quote:
In other words, all you have to do in a managed environment is call EntityManagerFactory.getEntityManager() or inject the EntityManager, do your data access work, and leave the rest to the container. Transaction boundaries are set declaratively in the annotations or deployment descriptors of your session beans. The lifecycle of the entity manager and persistence context is completely managed by the container.


I would like to use the bold approach.

In my code I use this method to get the entity manager (code from documentation):
Code:
EntityManager em = factory.getEntityManager();

My 'factory' is created in a singleton class.

I searched Hibernate Annotations documentation and forum and didn't find any mention about the way I should demarcate the transactions using annotations.

Could somebody direct me to a resource describing the annotation to be used or just write "do it this way"?

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 11:40 am 
Newbie

Joined: Thu Nov 24, 2005 8:48 am
Posts: 10
I have also find this:
Quote:
In EJB 3.x you can use JDK 5.0 annotation metadata directly in your source code, a much less verbose approach.

here:
http://www.hibernate.org/42.html#A8
It is also not very verbose.

I haved looked into EJB3 draft and found out some annotations like @Stateless, @Stateful, @Transaction etc. But I didn't find these in any of the jars packed with hibernate packages.

These annotations above are used in class scope but I would prefer to have it for a method scope.

I have also found this:
Quote:
Container-managed datasources: Hibernate can use JDBC connections managed by the container and provided through JNDI. Usually, a JTA compatible TransactionManager and a ResourceManager take care of transaction management (CMT), esp. distributed transaction handling across several datasources. You may of course also demarcate transaction boundaries programatically (BMT) or you might want to use the optional Hibernate Transaction API for this to keep your code portable.

here:
http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#configuration-j2ee

The code portability using Hibernate Transaction API seems the best solution for me but I don't know how to use it in CMT. I'll try to find out more.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 1:30 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I don't know JOTM very well, but this only a JTA implementation, not a CMT environment. Tx are not declared declarativelly in JOTM, you'll have to use an EJB container.
Try JBoss EJB3 embeddable, It works from tomcat and has all the needed features you want. You can also make it work form you junit tests.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 1:44 pm 
Newbie

Joined: Thu Nov 24, 2005 8:48 am
Posts: 10
Thank you for your answer, Emmanuel. I'll try the JBoss.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.