-->
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.  [ 15 posts ] 
Author Message
 Post subject: How to get the id generator type from the HBM file???
PostPosted: Thu Aug 18, 2005 5:34 am 
Newbie

Joined: Thu Dec 23, 2004 3:53 am
Posts: 19
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0.5

Name and version of the database you are using:
Oracle 9.2

I need to know if the type of it is assigned or not?

Thanks


Top
 Profile  
 
 Post subject: Did you tryy using the Configuration object
PostPosted: Thu Aug 18, 2005 11:27 am 
Newbie

Joined: Thu Aug 18, 2005 3:22 am
Posts: 13
Hi,

you can use the org.hibernate.cfg.Configuration object to retrieve information on the configuration.
Something like
Iterator it = config.getTableMappings();
while(it.hasNext()){
Mapping m = (Mappings)it.next();
PersistentClass pc = m.locatePersistentClassByEntityName(relevantEntityName);
if(pc != null){
Property idProp = pc.getIdentifierProperty();
// examine property to find out the id generator
}
}

Regards
Guido


Top
 Profile  
 
 Post subject: Configuration object??
PostPosted: Sun Aug 28, 2005 3:05 am 
Newbie

Joined: Thu Dec 23, 2004 3:53 am
Posts: 19
How to get the Configuration object associated with my hbm files?
Just create new one??

Thanks.


Top
 Profile  
 
 Post subject: You needed it for the SessionFactory
PostPosted: Sun Aug 28, 2005 5:25 am 
Newbie

Joined: Thu Aug 18, 2005 3:22 am
Posts: 13
You must have inititlized an instance of it to init the SessionFactory, haven't you?

Regards
Guido


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 28, 2005 5:37 am 
Newbie

Joined: Thu Dec 23, 2004 3:53 am
Posts: 19
I did but how do I get that instance?


Top
 Profile  
 
 Post subject: I dont see your point
PostPosted: Mon Aug 29, 2005 2:20 am 
Newbie

Joined: Thu Aug 18, 2005 3:22 am
Posts: 13
Can you please post the code lines that init your SessionFactory?

Regards
Guido


Top
 Profile  
 
 Post subject: Spring
PostPosted: Mon Aug 29, 2005 3:25 am 
Newbie

Joined: Thu Dec 23, 2004 3:53 am
Posts: 19
The SessionFactory is init by Spring


Top
 Profile  
 
 Post subject: Create a new Configuration object
PostPosted: Mon Aug 29, 2005 4:02 am 
Newbie

Joined: Thu Aug 18, 2005 3:22 am
Posts: 13
I see. It should not be a problem to create a new Conifuration object that reflects your config using org.hibernate.cfg.Configuration. At least you need to have access (or know the location) to your configuration file.
You should destroy the configuration object after your examination. I am not sure if a new config object causes any trouble because of singleton issues but I do not think so.

Regards
Guido


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 29, 2005 5:30 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Ask to Spring guys how to access your Configuration object, it is useful in some interesting cases. Your integration framework must not limit you.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Isn't Hibernate also a framework?
PostPosted: Mon Aug 29, 2005 2:16 pm 
Newbie

Joined: Thu Aug 18, 2005 3:22 am
Posts: 13
Thus, a getConfiguration on the SessionFactory would also be helpful. When you get a DataSource from your servlet container you do not have any information on the connection as well. Maybe sometimes it is also good to hide away things from users in frameworks.

regards
Guido


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 29, 2005 2:23 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the configuration is a mutable thing so it should not be available on the SessionFactory.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 29, 2005 2:30 pm 
Newbie

Joined: Thu Aug 18, 2005 3:22 am
Posts: 13
I see. I did not know that it can be modified.
But would it cause a problem to generate a new one just to find out some things? Because this might answer the original question of this thread.

Regards
Guido


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 29, 2005 2:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well why doesnt he just keep it around (generating wont be wrong if its initialized with the same input), but otherwise as far as i remember spring exposes a getConfiguration() somewhere - but i dont know the spring api by heart.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: my solution
PostPosted: Tue Aug 30, 2005 3:10 am 
Newbie

Joined: Thu Dec 23, 2004 3:53 am
Posts: 19
The only way I managed it is when I get the Configuration object in the MyLocalSessionFactoryBean class I save it in other class that I have access to.


Top
 Profile  
 
 Post subject: accessing sessionfactory Configuration in Spring
PostPosted: Tue Aug 30, 2005 6:31 am 
Newbie

Joined: Thu Nov 25, 2004 11:44 am
Posts: 15
Location: Woodbridge UK
If you need access to the Configuration object, then subclass LocalSessionFactoryBean and override postProcessConfiguration

@Override
protected void postProcessConfiguration(Configuration config) throws HibernateException
{

Iterator classes = config.getClassMappings();
Settings settings = config.buildSettings();

while (classes.hasNext())
{
PersistentClass model = (PersistentClass) classes.next();
if (!model.isInherited())
{

KeyValue identifier = model.getIdentifier();

if (identifier instanceof SimpleValue)
{
SimpleValue sv = (SimpleValue) identifier;

String identifierGenerator = sv.getIdentifierGeneratorStrategy();
}

}

}

}

You can save your results in this spring bean. To access it, don't forget to use the Spring factory bean dereference identifier (&), otherwise getBean() will return a SessionFactory rather than a your FactoryBean instance


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