-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to detach object and get rid of proxes and lazy stuff?
PostPosted: Fri Jul 21, 2006 10:22 am 
Newbie

Joined: Wed Aug 10, 2005 8:54 am
Posts: 10
hi all.

i want to complettly detach object. complettly i mean not just detach from hibernate session but also get rid of lazy sets and proxys.

i know it is against hibernate ideology but look:

i have somme kind of "ajax like" javascript client invented long time ago (before xmlhttprequest) in my company. now we want to replace perl with java. this JS clietnt communittes with java business tier via Strings.
while business trier returns somme data than my communication engine iterates through all objects (and recursively through all theri getter methods) and converts them to string (in special format).

so when my converter get somme lazy collection than exception is thrown:/

example:

suppose we have persistsent class:

class Person{
private String name;
//... other person attributes

//==== relations =====
private PersonType perosnType;
private Set documents;
//...... getters and setters
}

when i query for person i want JUST persons attributes. i dont care about type and documenst so i would like to have them set null. i NEED null values instead of proxys bacause my converting engine (that iterates throuh all getters) will crash on them. ofcourse sommetimes i want to fetch deeply but i need to stop getter recursion sommewhere;)

is there any posibility to completlly detach object? (manually setting null doesnt satisfact me;)

thanks for help and Your time


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 3:08 am 
Newbie

Joined: Wed Aug 10, 2005 8:54 am
Posts: 10
currently my idey is to browse query results, detec proxies and lazy sets (catching Exceptions) and set'em null.
im affraid that it is a little;) not optimal - especially catching exceptions

have You guys got any ideas how to solve it?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 05, 2007 10:00 am 
Newbie

Joined: Mon Feb 05, 2007 9:50 am
Posts: 1
Hi slawek,

we've the same problem - but no solution. We are trying to filter the set of objects via sql where-clause. So some hibernate sets "aren't fully initialized". When we try to access the sets, the NonIntializedException is thrown.

After research i found these interesting postings:
- http://www.hibernate.org/377.html
- http://forum.hibernate.org/viewtopic.php?t=969741
- http://forum.hibernate.org/viewtopic.php?t=964452
- http://forum.hibernate.org/viewtopic.php?t=936206

So, do you solved the problem?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 05, 2007 3:14 pm 
Regular
Regular

Joined: Wed Dec 07, 2005 4:19 pm
Posts: 53
If you look at what Hibernate.intialize(Object o) does, it only cares about objects of either HibernateProxy.class or PersistentCollection.class.

I am using this fact to (recursively) intialize the entire object graph, using introspection to walk the object members. With recursion it gets a bit complicated watching for cyclical trees, but it works.

So I would assume you could do something similar: walk your objects, look for members that are instances of the above classes, and setting them to null (if that's what you want) OR initialize them at that point (and recurse on other objects).

(plase rate this post in case it helped).
Martin.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 06, 2007 5:08 am 
Newbie

Joined: Wed Aug 10, 2005 8:54 am
Posts: 10
no, i didnt solve it:/
actually just few business functions needed our silly JS client so we have created DTOs that are created in business tier.

this
http://forum.hibernate.org/viewtopic.php?t=964452
looks like solution for my problem now.

but i think programing this way and using hibernate in such cases is like 'putting on your pants through your neck' (or sth;)


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