Tapestry's built-in Hibernate/JPA support is very close to OpenSessionInView.
It's lazier, I believe, than Springs. The Session is created on first usage (via the magic of lazy proxies). In any case, the transaction extends to the end of the request, and is then aborted. The challenge is never dealing with the entities during a single request; its dealing with same entities across multiple requests. With Tapestry, what gets persisted across requests is not a (detached) entity instance, but instead the entity's id: as a (typically) numeric string in a URL, in a hidden field, or in the HttpSession. On a later request, the entity is reconstituted from the id: from Hibernate's cache, or from the database. The challenge here is that wizards can be difficult. In a wizard, you want to render a series of pages (or even Ajax updates to a single page) to modify different features of an entity, including adding, modifying, and removing related entities (for example, the LineItems in an Order). In some models, you would detach the entity and store it in the HttpSession for a while ... make changes, then reattach it to update the database. This is notoriously tricky in Hibernate, as relationships from the entity to other entities can cause lazy instantiation errors. One of the reasons I'm very much liking document databases, such as MongoDB, is that what would be encoded as a graph of entities in a ORM becomes a single JSON document, that even has a natural string representation for ease of transfer between server and client. However, more than that, the direction the web is going (and where I hope to bring Tapestry in 5.4) is that the basic HTTP/HTML Form paradigm is outdated and should be abandoned except for the most trivial cases. For complex wizards, the UI should be dynamic on the client to whatever degree is necessary, and the very last thing is to send a package of updates to the server via Ajax. This is the approach you see with client-side MVC frameworks such as Backbone.js, Spine, SproutCore, etc. So, what do you do today? In some ways, you best bet is to create DTOs that are not entities, and contain just the values to be edited in your wizard. The DTOs are created from a Hibernate entity in one transaction, can be updated across multiple transactions (persisted in the HttpSession). At the end of the process, the DTOs can be used to update the Entities. It's not perfect; in a dynamic language environment such as Groovy or Ruby you would just use maps for the DTOs, but in Java (and Tapestry) you tend to create proper JavaBeans to let Tapestry leverage types and annotations (though I would tend to create dumb objects with public fields, rather than the whole getter/setter/private-field shenanigans). There is not one simple answer, but as in many situations, the guide should be the content of your use case, rather than the schema of your database. On Tue, May 22, 2012 at 10:21 AM, bhorvat <horvat.z.bo...@gmail.com> wrote: > > OpenSessionInViewFilter has nothing to do with detached entities, it only > keeps session open till view is rendered otherwise lazy loading will no > work. The filter is trying to solve it by always opening session in every > request and closing it at the end. Tapestry hibernate opens session only > when it is needed and closes it when thread is finished, it is how it should > be, but if you use spring hibernate + tx you need to use it there is no way > around it. >> >> -- >> View this message in context: >> http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713314.html >> Sent from the Tapestry - User mailing list archive at Nabble.com. >> > > So just to clarify the tapestry-hibernate now does the same thing as OSIVF > only better, right? Sorry for all the repetition but it is confusing a bit > :) > > cheers > > -- > View this message in context: > http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713326.html > Sent from the Tapestry - User mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > -- Howard M. Lewis Ship Creator of Apache Tapestry The source for Tapestry training, mentoring and support. Contact me to learn how I can get you up and productive in Tapestry fast! (971) 678-5210 http://howardlewisship.com --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org