-->
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.  [ 7 posts ] 
Author Message
 Post subject: EntityManager class autodetect issue
PostPosted: Wed Jan 03, 2007 9:40 pm 
Regular
Regular

Joined: Thu Jul 29, 2004 11:55 pm
Posts: 75
I am using Hibernate/Annotations/EntityManager 3.2.1 GA in JSE and I am having a problem with the EntityManager not loading classes from a directory other than the base where the persistence.xml resides. Here is my scenario:

I am using Maven2 as my build environment and it creates the source class output in the ./classes directory and the test classes in the ./test-classes directory. In the ./classes directory, resides the persistence.xml that I use when I deploy my classes to JBoss. In my ./test-classes directory, I have a persistence.xml that is needed for unit testing (outside of the jboss enviroment). Since the EntityManager uses this persistence.xml to create the EntityManagerFactory, it doesn't find any of my annotated classes because they exist in the classes directory. Is there anyway to get the entity manager to search the full classpath (I know this adds a ot of overhead) or a way to specifiy an override directory (this would probably require a hibernate specific property). Or does anyone know of a different way to solve this problem?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 03, 2007 11:35 pm 
Newbie

Joined: Wed Aug 03, 2005 2:13 am
Posts: 16
Hi,

I'm still an ant man, having managed to avoid maven so far. But if you run your tests with the classpath including the classes and test-classes directory, then this should work fine. It's what I'm doing for unit testing EJB3 using the ejb3 embedded container.

You'd think this is how maven would be running your tests by default, so I'm not sure what the problem is. In ant, I have something like:
Code:
   <path id="junit.classpath">
      <fileset dir="${lib.dir}/ejb3-embedded">
         <include name="*.jar" />
      </fileset>
      <pathelement location="${test.classes.dir}" />
      <pathelement location="${classes.dir}" />
      <pathelement location="${lib.dir}/ejb3-embedded/conf" />
...
...
...
   </path>


As long as I put "test.classes.dir" above my "class.dir", the correct persistence.xml gets picked up, and it finds my persistent class fine.


hope it helps,
D.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 2:11 pm 
Regular
Regular

Joined: Thu Jul 29, 2004 11:55 pm
Posts: 75
Are you bootstrapping the EntityManager or are you letting the ejb embedded container provide the EntityManager ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 6:16 pm 
Newbie

Joined: Wed Aug 03, 2005 2:13 am
Posts: 16
I'm bootstrapping it myself. Here's my test setup code:
Code:
        EJB3StandaloneBootstrap.boot(null);
        deployer = EJB3StandaloneBootstrap.createDeployer();       
        deployer.getArchivesByResource().add("META-INF/persistence.xml");
        deployer.create();
        deployer.start();
       
        ctx = new InitialContext();     
        em = (EntityManager) ctx.lookup("java:/EntityManagers/localUnitTestEM");
        tm = (TransactionManager) ctx.lookup("java:/TransactionManager");



ccanning wrote:
Are you bootstrapping the EntityManager or are you letting the ejb embedded container provide the EntityManager ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 05, 2007 8:02 pm 
Regular
Regular

Joined: Thu Jul 29, 2004 11:55 pm
Posts: 75
Thanks for the info. In your case, the embedded EJB3 is resolving the entity manager and the class paths most likely (you are getting the entity manager from the ejb3 jndi (Context). I am using Persistence.createEntityManagerFactory("persistence name);


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 05, 2007 8:07 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://opensource.atlassian.com/project ... se/EJB-232

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 12, 2007 7:33 pm 
Regular
Regular

Joined: Thu Jul 29, 2004 11:55 pm
Posts: 75
Thanks. That solved my problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.