-->
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: Programmatic discovery of entity EJBs.
PostPosted: Wed Feb 01, 2006 11:44 am 
Regular
Regular

Joined: Fri Jan 20, 2006 9:38 am
Posts: 61
Location: Notts, UK
I'm using Hibernate under JBoss/ejb3.

I'd like to be able to discover all the entity EJBs that Hibernate has found in my .par files. Is there a way of asking Hibernate for this info? Or do I have to search for .par files, and use the zip classes to examine them?

What I'm thinking about, is writing some kind of very basic data maintenance tool. It would offer create/update/delete for all known entities.

It would introspect them to find properties that are linked to database columns, see what types they are, and offer basic data manipulation.

How the user would select the rows... that I'm still thinking about. I could write some custom annotation classes to add to @column properties that are to be "keys", and these could be offered to find matches.

Anyway, any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 12:16 pm 
Regular
Regular

Joined: Fri Jan 20, 2006 9:38 am
Posts: 61
Location: Notts, UK
Well, it's something to do with getting a

javax.persistence.spi.PersistenceUnitInfo

And calling

getManagedClassNames

List<String> getManagedClassNames()

Returns:
The list of the names of the classes that the persistence provider must
add it to its set of managed classes. Each name corresponds to a
named element in the persistence.xml file.

I imagine that includes managed classes discovered through looking for annotations because we don't name our entities in persistence.xml.

But how does one get a javax.persistence.spi.PersistenceUnitInfo?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 1:39 pm 
Beginner
Beginner

Joined: Fri Jan 14, 2005 7:47 am
Posts: 37
Location: Spain
The next code work for your goal:

Code:
   private static Collection<String> getManagedClassNames() {
      if (managedClassNames == null) {
         // The next code is Hibernate dependent.
         // This code has to be modified in order to work with Glassfish, OpenJPA, etc.
         EntityManager manager = XPersistence.createManager();
         org.hibernate.impl.SessionImpl impl = (org.hibernate.impl.SessionImpl) manager.getDelegate();
         managedClassNames = impl.getSessionFactory().getAllClassMetadata().keySet();
         manager.close();                  
      }
      return managedClassNames;
   }


But it's hibernate dependent. Sorry!

Maybe there is a better way

Cheers
Javier Paniza


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.