-->
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: Howto retrieve the configuration at runtime?
PostPosted: Sun Apr 30, 2006 6:10 pm 
Newbie

Joined: Sun Apr 30, 2006 6:06 pm
Posts: 1
After successfully setting up Hibernate Annotations and Entity manager, I need to retrieve the configuration (as read through e.g. the persistence.xml file) to list the classes that will be persisted.

I've look through the API doc's and some other documentation but am not able to find any clue. Does any of you have an answer?

@eyall: Thanks a lot. Solved my problem. (I'm still wondering what to do with non-Hibernate implementations however).


Last edited by vanos on Thu May 04, 2006 6:16 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 4:11 am 
Beginner
Beginner

Joined: Wed Aug 24, 2005 5:32 am
Posts: 23
Hi,
You can get the Hibernate session factory, on the session factory you can call the getAllClassMetadata() method, for example

Code:
      
HibernateEntityManager entityManager2 = (HibernateEntityManager)entityManager;
      SessionFactory factory = entityManager2.getSession().getSessionFactory();
      Map m = factory.getAllClassMetadata();
      Set<Map.Entry> s = m.entrySet();
      for (Map.Entry e : s) {
         System.out.println(e.getKey() + "--->" + e.getValue());
      }


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 4:25 am 
Beginner
Beginner

Joined: Wed Aug 24, 2005 5:32 am
Posts: 23
Hi,

You can get the Hibernate session factory, on this session factory you can invoke the getAllClassMetadata() method, for example

Code:
      
HibernateEntityManager entityManager2 = (HibernateEntityManager)entityManager;
SessionFactory factory = entityManager2.getSession().getSessionFactory();
Map m = factory.getAllClassMetadata();
Set<Map.Entry> s = m.entrySet();
for (Map.Entry e : s) {
      System.out.println(e.getKey() + "--->" + e.getValue());
}


will print:
Code:
par.common.Address--->SingleTableEntityPersister(par.common.Address)
par.common.Customer--->SingleTableEntityPersister(par.common.Customer)
par.common.Catalog--->SingleTableEntityPersister(par.common.Catalog)
par.common.Service--->SingleTableEntityPersister(par.common.Service)
par.common.InternalService--->SingleTableEntityPersister(par.common.InternalService)
par.common.ExternalServiceTwoProviders--->SingleTableEntityPersister(par.common.ExternalServiceTwoProviders)
par.common.Attribute--->SingleTableEntityPersister(par.common.Attribute)
par.common.ExternalService--->SingleTableEntityPersister(par.common.ExternalService)


If you don't want to get an entity manager and cast it to Hibernate entity manager, and get the session factory out of it. You can add to your persistence.xml the 'hibernate.session_factory_name' property and ask Hibernate to register the session factory to a JNDI (assuming that you have one).

Eyal Lupu


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 4:28 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I thnik I'll provide the Configuration object available in JNDI

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 3:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
but hopefully also available elsewhere in standalone programs ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 2:18 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Where?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 4:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
((somemagiccast)entitymanager).getConfiguration() ? :)

_________________
Max
Don't forget to rate


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.