[jboss-jira] [JBoss JIRA] (HIBERNATE-133) Function to detach Hibernate managed object.

jack luo (JIRA) jira-events at lists.jboss.org
Mon Jul 15 17:44:26 EDT 2013


    [ https://issues.jboss.org/browse/HIBERNATE-133?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12789795#comment-12789795 ] 

jack luo commented on HIBERNATE-133:
------------------------------------

It's been a year now and there's no update at all...
                
> Function to detach Hibernate managed object.
> --------------------------------------------
>
>                 Key: HIBERNATE-133
>                 URL: https://issues.jboss.org/browse/HIBERNATE-133
>             Project: Hibernate Integration
>          Issue Type: Feature Request
>         Environment: Hibernate core.
>            Reporter: jack luo
>            Assignee: Steve Ebersole
>              Labels: LazyInitializationException
>
> Currently, after retrieving data from database by hibernate like:
> User user = session.get(User.class, id);
> Then user object will become a hibernated managed object (po), if try to invoke any "lazy" property which haven't been initialized then it will throw an famous "LazyInitializationException". But so often, in web service or other scenarios, we need to serialize the object returned by Hibernate query, serializer doesn't know which properties are "lazy" field and haven't been initialized, then in serializing, it will throw an ""LazyInitializationException" exception which will stop the whole thing working. I found Session.evict(Object proxy) and Session.clear() seems might do the work that detaching PO from Hibernate, but it doesn't. I still got the error. After spent days searching in the internet, I found out there isn't any easy way to convert an PO to a POJO (detaching PO from Hibernate thoroughly), actually many people have implemented so many solutions like removing all the proxies from PO or copy PO to an POJO (DTO some people call it), any solution comes with cost of the system apparently. Well, if Hibernate can provide a simple function Hibernate.detach(Object obj) which will return an pure POJO then it will make our life so much easier. Check this link out, you see how many people have been struggling with this issue since 2008? 
> http://www.mojavelinux.com/blog/archives/2006/06/hibernate_get_out_of_my_pojo/
> My first try on Hibernate was back to 2007 and I found this issue, ending up copying properties of PO to a POJO to avoid "LazyInitializationException" exception. I absolute got the idea of lazy loading but DAO layer will pass the object to Business/View layer, I don't think they're responsible to check if every property's initialized by Hibernate before using it. It ok that un-initialized properties are null but throwing an exception is unacceptable. Requirement is quite straight forward, just want a pure POJO.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira



More information about the jboss-jira mailing list