Re: [Beankeeper-discussion] BeanKeeper instance identity.
Brought to you by:
demonsystem
From: Sergey O. <so...@gm...> - 2011-12-09 20:03:48
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> </head> <body text="" bgcolor=""> <br> With Hibernate everything you load within the scope of one Session (which for e.g. web application you'd usually set to span the entire request processing) is guaranteed to have one Java instance per one database object / row -- i.e. no matter how you load the object, it'll resolve to the same Java instance.<br> <br> <a class="moz-txt-link-freetext" href="http://docs.jboss.org/hibernate/core/3.3/reference/en/html/transactions.html">http://docs.jboss.org/hibernate/core/3.3/reference/en/html/transactions.html</a><br> "For objects attached to a particular Session (i.e., in the scope of a Session), the two notions are equivalent and JVM identity for database identity is guaranteed by Hibernate."<br> <br> The same is true for general JPA. This is basically has been a cornerstone on which Hibernate / JPA is built. That's why I was so surprised it's not apparently true for BeanKeeper.<br> <br> For what it worth, I've done a bit of code digging and I'm going to bet that indeed in BeanKeeper if you reach a database object instance / row via different paths (via different query or by following a different set of collections) -- you'll have a different Java instance unlike traditional ORM.<br> <br> It also seems that it would be trivially easy to add some kind of Session support to BeanKeeper, but it cannot be done externally (requires modification of BeanKeeper's code directly).<br> <br> However after actually trying to develop minor application on BeanKeeper I found other limitations and shortcomings -- particularly inability to have attribute with the same name in two classes if they share a common parent and incompatibility with most recent HSQLDB. So it seems a serious risk to invest into BeanKeeper as it shows that it hasn't been developed/maintained for a while. But given how much I like it conceptually, I might still give it a shot.<br> <br> It's a pity it hadn't gained a following and seems to be 'mostly dead' for now as it seems it truly has serious potential as a proper way to do objects persistence in Java without all the mess associated with even good ORM (Hibernate) to say nothing of a worse solutions (EJB pre version 3 anyone?).<br> <br> On 09.12.2011 21:02, Marcel Stör wrote: <blockquote cite="mid:4EE...@fr..." type="cite"> <pre wrap="">On 08.12.11 16:31, Sergey Olefir wrote: </pre> <blockquote type="cite"> <pre wrap="">Hi, I am not sure if this list is even alive anymore, but let's see :) </pre> </blockquote> <pre wrap=""> I didn't get a message in years. So yeah, I'll be interested myself. </pre> <blockquote type="cite"> <pre wrap="">Recently I've been trying to use BeanKeeper. It seemed to cover mostly what I need and is very simple to use -- which is great! However now I discovered something that has me completely confused. I assumed that BeanKeeper manages Java object instances -- to give a really trivial example -- if I query for something by its unique ID twice, I'd expect to receive the same Java object instance both times. However this not appears to be the case? </pre> </blockquote> <pre wrap=""> I don't know for sure but I wouldn't be surprised if what you're seeing is the expected behavior. I realize that there may be use cases where such a behavior would be helpful but AFAIK you can't count on it with any ORM tool. With Hibernate for example you could achieve what you want only if use a second level cache (if I'm not mistaken). </pre> <blockquote type="cite"> <pre wrap="">For example, if I execute the following twice in a row: log.info("Offer lookup result HASH: " + System.identityHashCode(DbService.findSingle("find DbOffer where DbOffer.offerId = '" + offer.getId() + "'"))); I get different hash codes. This seems very weird to me -- how do I work with a rich data model when I can't count on the same object to be represented by the same instance? For example, I have two different paths to the same instance via Lists and Maps -- and it seems that I'll be working with different instance depending on which path I take -- and if I use both paths, it'll probably result in a mess. Am I missing something here? Best regards, Sergey ------------------------------------------------------------------------------ Cloud Services Checklist: Pricing and Packaging Optimization This white paper is intended to serve as a reference, checklist and point of discussion for anyone considering optimizing the pricing and packaging model of a cloud services business. Read Now! <a class="moz-txt-link-freetext" href="http://www.accelacomm.com/jaw/sfnl/114/51491232/">http://www.accelacomm.com/jaw/sfnl/114/51491232/</a> _______________________________________________ Beankeeper-discussion mailing list <a class="moz-txt-link-abbreviated" href="mailto:Bea...@li...">Bea...@li...</a> <a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/beankeeper-discussion">https://lists.sourceforge.net/lists/listinfo/beankeeper-discussion</a> </pre> </blockquote> <pre wrap=""> </pre> </blockquote> </body> </html> |