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.  [ 3 posts ] 
Author Message
 Post subject: How are the persistence classes in root of unit located?
PostPosted: Fri Mar 10, 2006 11:09 am 
Newbie

Joined: Fri Mar 10, 2006 8:36 am
Posts: 2
In section 6.2.16 of the java persistence spec (Final draft) I read the following:

Quote:
The set of managed persistence classes that are managed by a persistence unit is defined by using one or
more of the following:
...

The annotated managed persistence classes contained in the root of the persistence unit (unless
the exclude-unlisted-classes element is specified)


How does the current version of Hibernate handle this? I'm using Hibernate Core 3.1.1 with Annotations 3.1b8 and EntityManager 3.1b6 in combination with Tomcat 5.5.15 and Sun JDK 1.5u6 on Windows XPsp2.

If I list the classes explicitly in my persistence.xml, everything works as expected and I can make use of a lot of EJB3 facilities. However, as soon as I remove the explicit class listing, everything Hibernate tries to lookup (e.g. named queries, entities, etc) fails. E.g. I get exceptions like: org.hibernate.MappingException: Named query not known: MyClass.MyQuery

I didn't set the exclude-unlisted-classes element, but even if I would have done that, it doesn't seem to be used in the source code. PersistenceMetadata.java has a getExcludedUnlistedClasses method, but it's just never called from anywhere (or so it seems).

I tried to work my way through the initialisation part of an entity manager, but I can't spot the code anywhere that scans the root of the persistence unit for classes that contain EJB3 annotations.

Specifically, the parts that puzzle me are:

Code:
In EJB3Configuration.createFactory:
 
  if ( metadata.getClasses().size() > 0 ) {
   workingVars.put( HibernatePersistence.CLASS_NAMES, metadata.getClasses() );
  }
 


In Ejb3Configuration.createEntityManagerFactory:

  if ( workingVars.containsKey( HibernatePersistence.CLASS_NAMES ) ) {
      // check and add to cfg.annotatedClasses CLASS_NAMES ultimately come from persistence.xml

  }

  if ( workingVars.containsKey( HibernatePersistence.LOADED_CLASSES ) ) {
      // check and add to cfg.annotatedClasses. LOADED_CLASSES are never inserted anywhere (?)
  }

  // ...

  listenerConfigurator.configure() -> ... -> AnnotationConfiguration.secondPassCompile ->
  // process annotations in classes and fill cfg.classes Map.



It seems though that HibernatePersistence.LOADED_CLASSES should be the key under which the classes from the root of the unit are stored, but this key is never inserted, nor could I locate any code that attempts this.

Did I just overlook something? I know that other people don't list their classes at all in persistence.xml and they still get processed by Hibernate, so where could the code be that does this? Why would it possible not work in my situation?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 12:05 pm 
Newbie

Joined: Fri Mar 10, 2006 8:36 am
Posts: 2
I just examined a system on which the entire root of the pu IS scanned, and found out that this scanning takes place in Ejb3Configuration -> addMetaDataFromVisitor. This uses the ExplodedJarVisitor that walks through all classes in the class tree and checks for the requried annotations.

All classes that pass this test are added to the PersistenceMetadata.classes collection. (since this is a general collection of class names, they get checked again later, maybe in systems that have thousands of entity classes this may be a performance issue?)

The (linux) system on which I tested uses the exact same source code and project configuration (fresh checkout from CVS). Also this other test machine uses the exact same version of hibernate, tomcat and java vm.

I wonder why scanning the pu root for classes works on one machine, but not on the other.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 12, 2006 2:56 pm 
Newbie

Joined: Sun Mar 12, 2006 11:00 am
Posts: 1
atijms wrote:

I wonder why scanning the pu root for classes works on one machine, but not on the other.


I had the same issue recently.

This concerned two nearly identical configured Windows machines. Upon deploying the same web application to both machines, one of them would find the entities in my packages while they other didn't. On the machine that failed to find any entity I had to explictly list them in persistence.xml. After doing that both machines worked succesfully, but it's strange I had to specify my classes on one machine and not the other.


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