Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Possible to have Hibernate hydrate objects with Factory?
PostPosted: Thu Jun 03, 2004 11:14 am 
Regular
Regular

Joined: Fri Sep 12, 2003 12:40 pm
Posts: 65
Gavin/Christian/et al.

In lieu of the default constructors, is it possible (in some manner) to create a plugin or adapter that would hydrate objects from the database using a specified Factory vs. the default constructors?

I'm interested in this because I'd like to have the objects be retrieved from a database as an XML entity using xmlbeans.

See this post from the xmlbeans-dev mailing list for one of the more recent posts about how XMLbeans requires objects to be created.

I volunteered to take a look at this topic for the XMLbeans group. I'm not sure that I'm most qualified to do it, but I do have a lot of interest in: 1. binding xml documents that satisfy a given schema to a java object and subsequently back to a relational store (using hibernate).

Thanks.

_________________
- Brian


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 2:53 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7179
Location: Atlanta, USA
This is not possible right now. Maybe it's a good feature.

_________________
Emmanuel
Check Hibernate Search in Action out


Top
 Profile  
 
 Post subject: Thanks, but...
PostPosted: Thu Jun 03, 2004 8:59 pm 
Regular
Regular

Joined: Fri Sep 12, 2003 12:40 pm
Posts: 65
Thanks emmanuel.

I'm interested in changing the object creation behavior of the elements in Hibernate: how they're created and where they're created from.

e.g. If I ask for:

Code:
select foo from com.paraware.Foo as foo


and foo is related to bar and baz and lazy init is false, then I suspect hibernate does this:

Object foo = Class.forName.newInstance("com.paraware.Foo");
// figure out the properties of foo are and then:

Object bar = Class.forName.newInstance("com.paraware.Bar");
foo.setBar(bar);
// find the properties of bar and

Object baz = Class.forName.newInstance("com.paraware.Baz");
bar.setBaz(baz);

etc.

Obviously hibernate uses cglib and reflection to do this sort of thing (i.e. it's not hardcoded as in my example), but I am curious how it navigates the graph and where object creation takes place.

I'm interested to specify that for certain objects, hibernate be allowed to use either a factory or a creation method (newXXX) from the parent within the graph as in:

Foo foo = Foo.Factory.newIntance(); // use the Factory and newInstance method to create new objects
Bar bar = Foo.newBar(); // use the newBar() method of Foo to create and set Bar objects
Bar.setBaz( 123 );

I'm not sure how this plays into collections, etc, but I was wondering if it was possible, where a good entry point might be.

_________________
- Brian


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 04, 2004 12:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1812
Location: Austin, TX
This is totally doable. In fact you have two options:
1) create a custom ClassPersister implementation;
2) create a custom Interceptor implementation, specifically the Interceptor.instantiate() method will be of interest to you...


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