Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: XDoclet + Hibernate followup
PostPosted: Wed Aug 27, 2003 9:15 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 8:55 am
Posts: 28
Location: Dallas, TX
Last week I posted a question on the old forum regarding how to easily load all of the Hibernate configuration files that XDoclet can generate. Basically, my question was, "If you are dynamically generating all of the *.hbm.xml files, what is an easy way to slurp all these files in to configure you SessionFactory?"

Well...I discovered the lastest CVS of XDoclet 1.2 has a Ant subtask for this very purpose: factoryclass. Basically, it generates a class that "knows" about all of the generated configuration files and loads them for you. All you have to do is add this subtask to your hibernatedoclet task like so:

[code]<factoryclass factoryclass="foo.bar.SessionFactoryFactory"
driver_class="oracle.jdbc.driver.OracleDriver"
<!-- other properies go here -->
/>[/code]

Then, to get your SessionFactory, all you have to do is:

[code]SessionFactory factory = SessionFactoryFactory.getSessionFactory();[/code]

You will never have to touch this again, no matter what changes you make to your persistable classes. I hope this is of some use to some people.

Ryan


Top
 Profile  
 
 Post subject: hibernate.properties
PostPosted: Wed Aug 27, 2003 1:32 pm 
Beginner
Beginner

Joined: Tue Aug 26, 2003 6:24 pm
Posts: 45
if using SessionFactoryFactory, will hibernate.properties still be adhered to? I haven't tried it yet, but I'm confused by what config info must be added to SessionFactoryFactory generation.

I would like to (a) use hibernate.properties for general config and (b) use SessionFactoryFactory to automagically load all my hibernate classes.

Would this work? I'll try it out when I get a chance.
t


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2003 1:58 pm 
Beginner
Beginner

Joined: Wed Aug 27, 2003 8:55 am
Posts: 28
Location: Dallas, TX
You can actually configure this information both places - in the Ant subtask or a hibernate.properties file. It doesn't look like the subtask supports all of the properties (yet?).

I actually still keep the property information in a seperate file, like you described. Here is a snippet of what that would look like:

Code:
SessionFactory sessionFactory = null;
Properties properties = SessionFactoryFactory.getPropertyCache();
properties.load(IoUtils.getFileAsStream("hibernate.properties"));
sessionFactory = SessionFactoryFactory.getSessionFactory();


Basically, you get a hanlde to the Factory's properties, and then load your properties from the file. There may be a more elegant way, but this works for me.

HTH.

Ryan


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.