Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Query question, entity beans..

 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm learing Hibernate and its been great fun until now.
Please bare with me if I post naive questions:

'Detached Objects'...Why cant we have this feature with EJB Local objects!!. So even within the same VM I end up creating value objects that look similar to the local objects.

Anyways coming to my problem,

Say i have to represent a tree:

class NodeBean extends EntityBean{
Node parentNode;
Collection children;
}

Now if I have to send across this tree to the web tier from the server, I have to possibly run through each node, its children recursively and create corresponding value objects (ie exactly mimick the tree structure in the value objects as well).

So my question is, since Hibernate supports 'Detached' objects, will the root node have all its children already resolved, i mean is everything loaded from the database recursively?. That would mean that i just have to look up the root node and send it across to the web tier since the entire tree is 'contained' within the root!!?.

I have to investigate if weblogic's relationship caching can achieve the same!. setting <finder-load-beans> to true in the descriptor makes sure that all the beans are loaded upfront. But this setting does not apply to replationships. So am still not sure if cmr relationship caching implementation in weblogic can get me the entire object graph in one query.

OR

Does hibernate do a lazy load? In that case , the root node's children have not been recursively resolved. Now can this detached object, which is in the web tier, be traversed?

OR

There might be times when i want the entire object graph to be resolved and sometimes not. Can i do something at the query level then?
Fo eg can i write the HQL is a way that the entire tree is resolved during the first fetch itself?

For eg in weblogic , we can create field groups for immidiate fetch and associate the group with a query.


****************

CMR == container managed. This feature seems to be absent in Hibernate?. It expects me to manage both sides of say a bi-directional relationship.

But hibernate automatically persists all references reachable by an already peristent object. Figured that Hibernate calls it 'Persistance by reachability', i wonder what is it that entity beans implement then.

So even though the relationships are automatically managed by EJB the ejbCreate is not. So CMR manages relations as long as we are dealing with already persisted objects. Now i wonder if CMR is such a big deal compared to the persistance by reachablity offered by Hibernate?

Anyways guess enuf blabbering...but i have to admit that last few days have been quite exciting comparing these 2 technologies!

thanks.
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would be great if one of the authors could express their thoughts on this post i made long back.
thanks.
 
Gavin King
author
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While an object is attached (managed), Hibernate will trasparently load lazy associations. (You may even specify outer join fetching in the metadata or query.) As soon as the object is detached, it is no longer possible to fetch the association, and an exception will be thrown when the association is accessed.

Hibernate does not implement "managed" relationships in the sense of EJB2.1, in Hibernate, all persistent associations have the same behavior as ordinary Java associations.

In EJB entity beans, instantiation of entities is done by the container, in response to explicit user request. Hence the question of transitive persistence never arises ;-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic