Thread: [Beankeeper-discussion] BeanKeeper instance identity.
Brought to you by:
demonsystem
From: Sergey O. <ser...@we...> - 2011-12-08 15:31:53
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> </head> <body text="" bgcolor=""> Hi,<br> <br> I am not sure if this list is even alive anymore, but let's see :)<br> <br> 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!<br> <br> 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?<br> <br> For example, if I execute the following twice in a row:<br> log.info("Offer lookup result HASH: " + System.identityHashCode(DbService.findSingle("find DbOffer where DbOffer.offerId = '" + offer.getId() + "'")));<br> I get different hash codes.<br> <br> 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.<br> <br> Am I missing something here?<br> <br> Best regards,<br> Sergey<br> </body> </html> |
From: Marcel S. <ma...@fr...> - 2011-12-09 19:17:42
|
On 08.12.11 16:31, Sergey Olefir wrote: > Hi, > > I am not sure if this list is even alive anymore, but let's see :) I didn't get a message in years. So yeah, I'll be interested myself. > 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? 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). > 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! > http://www.accelacomm.com/jaw/sfnl/114/51491232/ > > > > _______________________________________________ > Beankeeper-discussion mailing list > Bea...@li... > https://lists.sourceforge.net/lists/listinfo/beankeeper-discussion -- Marcel Stör, http://www.frightanic.com Couchsurfing: http://www.couchsurfing.com/people/marcelstoer O< ascii ribbon campaign - stop html mail - www.asciiribbon.org |
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> |
From: Marcel S. <ma...@fr...> - 2011-12-09 20:08:12
|
On 09.12.11 21:03, Sergey Olefir wrote: > 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. Right, as long as the session-scope is what you're after that's correct. I thought your requirement was to get the same object for consecutive requests, sorry. Cheers, Marcel -- Marcel Stör, http://www.frightanic.com Couchsurfing: http://www.couchsurfing.com/people/marcelstoer O< ascii ribbon campaign - stop html mail - www.asciiribbon.org |
From: Bräutigam R. <de...@ne...> - 2011-12-13 19:46:14
|
On 12/08/2011 04:31 PM, Sergey Olefir wrote: > Hi, > > I am not sure if this list is even alive anymore, but let's see Hi, The list is alive and monitored, however BeanKeeper is not actively developed anymore. I still think its approach is a valid one, but unfortunately all the developers (the few we've had) moved on to other projects, including myself. > 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! Glad to hear that. > 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? You are correct, this is not the case, and on purpose. The reason is that BeanKeeper tries to be as simple as possible even if that means it does not fit all use-cases. BeanKeeper doesn't have any notion of a "Session" (of course it does have a notion of a Transaction though). It doesn't manage bean instances for you like Hibernate does. I believe for somebody not coming from Hibernate (which should be really rare these days), this is actually more intuitive. The rule is: any object you receive is completely clear, and does not in any way have any side-effects. It does not persist automatically, it does not influence other instances in your JVM, etc. > Best regards, > Sergey Robert. |
From: Sergey O. <so...@gm...> - 2011-12-14 09:53:11
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body text="" bgcolor=""> First of all -- thanks for replying!<br> <br> I can understand the logic behind not wanting to do Session mechanism -- even if I don't necessarily agree with it (because it makes working with persistent objects completely different from working with POJOs).<br> <br> With that said, I have a question. Let's take a look at the following pseudo-code (which is something I actually encountered trying to use BeanKeeper):<br> tx<br> {<br> a = find... // retrieve persistent object from BeanKeeper, it has 'list' property with list containing 2 elements.<br> instance1 = a.list.get(1);<br> instance1.update()<br> instance1.save()<br> instance2 = a.list.get(0); // Before 1 above -- this is important!<br> instance2.update()<br> instance2.save()<br> instance3 = a.list.get(1); // instance3 != instance1 at this point!!!<br> instance3.update2()<br> instance3.save()<br> }<br> txcommit<br> <br> As the result of all this I find that changes made in instance1.update() (to the instance1 fields) are NOT persisted. I'm guessing here that reading list backwards causes BeanKeeper to discard and recreate get(1) element because of performance optimizations (where it reads several items at once rather than just one). This in turn means that code operates on two different Java instances for get(1) and attempts to change and save both -- with changes made to instance1 subsequently lost.<br> <br> What I'm wondering about -- is this considered a bug or a feature? If it is a feature, what is the rule-of-thumb for working with BeanKeeper that'll prevent me from losing updates like the example above?<br> <br> Best regards,<br> Sergey<br> <br> On 13.12.2011 21:46, Bräutigam Róbert wrote: <blockquote cite="mid:4EE...@ne..." type="cite"> <pre wrap="">On 12/08/2011 04:31 PM, Sergey Olefir wrote: > Hi, > > I am not sure if this list is even alive anymore, but let's see Hi, The list is alive and monitored, however BeanKeeper is not actively developed anymore. I still think its approach is a valid one, but unfortunately all the developers (the few we've had) moved on to other projects, including myself. > 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! Glad to hear that. > 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? You are correct, this is not the case, and on purpose. The reason is that BeanKeeper tries to be as simple as possible even if that means it does not fit all use-cases. BeanKeeper doesn't have any notion of a "Session" (of course it does have a notion of a Transaction though). It doesn't manage bean instances for you like Hibernate does. I believe for somebody not coming from Hibernate (which should be really rare these days), this is actually more intuitive. The rule is: any object you receive is completely clear, and does not in any way have any side-effects. It does not persist automatically, it does not influence other instances in your JVM, etc. > Best regards, > Sergey Robert. ------------------------------------------------------------------------------ Systems Optimization Self Assessment Improve efficiency and utilization of IT resources. Drive out cost and improve service delivery. Take 5 minutes to use this Systems Optimization Self Assessment. <a class="moz-txt-link-freetext" href="http://www.accelacomm.com/jaw/sdnl/114/51450054/">http://www.accelacomm.com/jaw/sdnl/114/51450054/</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> </body> </html> |