-->
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.  [ 4 posts ] 
Author Message
 Post subject: Creation from factory instead of constructor?
PostPosted: Tue Sep 13, 2005 2:36 pm 
Newbie

Joined: Thu Aug 25, 2005 6:08 pm
Posts: 2
Using Hibernate 3.X

I would like Hibernate to use a factory (per class) to create objects when retrieving from the DB instead of invoking the default constructor, so that I can inject (IOC style) some facilities in those objects that are specific to the each class (e.g. resource managers).

I have tried with Events and interceptors, but those are application wide and therefore would require a big dispatcher that knows which factory to use for each class.

I have not seen any obvious configurations in the doc, and I was unable to find anything similar searching through the forums, wiki and Jira.

Any pointers would be greatly appreciated.

Miguel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 2:40 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
custom persister


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 4:45 pm 
Newbie

Joined: Tue Sep 13, 2005 4:07 pm
Posts: 5
Maybe this is the wrong way to do it, but I have my factories making the hibernate calls instead of hibernate calling the factory.

I wrote a factory for each class which all implemented a common interface. Then I wrote a builder for the factories, so my code looks like:

Factory f = FactoryBuilder.build(new CustomObject());

The factory builder builds the correct factory based on the object passed to it. Then in the factory I have simple methods like getObject, getObjects, etc. Each of these methods builds the appropriate hql for the object you are trying to get based upon what it was constructed with... so it should be easy to do your IOC stuff along with that.

I did it this way since it is easy to unplug hibernate and plug in jdbc or toplink and that was a requirement for development. Not sure if this is what you were looking for, but that's how I used custom factories with Hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 12:36 am 
Newbie

Joined: Thu Aug 25, 2005 6:08 pm
Posts: 2
Thanks a lot for the answers I think I'll try the persisters, as we do not see a need to migrate out of hibernate and I would like to leverage Criteria queries and related facilities.

To go the route for custom persisters, how does hibernate decide what persister to use? What are the rules to follow to know what persister to extend and how to attach it to hibernate?

Sorry for the ignorance, but this is the first time I get under the hood of hibernate and just discovering the big V8 under it.

Thanks again

Miguel

_________________
Miguel


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