Hi, use an ejb as LoginAction or set a transaction attribute on StoredCookie#persist (redefine it in StoredCookie)
*Romain Manni-Bucau* *Twitter: @rmannibucau <https://twitter.com/rmannibucau>* *Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/> *LinkedIn: **http://fr.linkedin.com/in/rmannibucau* *Github: https://github.com/rmannibucau* 2013/8/16 Howard W. Smith, Jr. <[email protected]> > Lee, I will let someone else answer your questions, but your test case > reminded me of a BalusC (JSF guru) blog[1] that I visited many months ago. > It does not answer your question, but it is an alternate solution for what > you are already attempting to do...I think. :) > > [1] http://balusc.blogspot.com/2007/03/user-session-filter.html > > > On Fri, Aug 16, 2013 at 6:10 AM, leesy <[email protected]> wrote: > > > I'm having trouble getting my head around Java EE, transactions & lazy > > loading & I was wondering if anyone could be kind enough to help me get > > things straight in my head. It's something I've never quite got right. > > I'll try & keep the code samples in this email short, but I'll add links > to > > fuller examples at the end. Sorry if this was better on say the OpenJPA > > Users list. > > > > I've got a piece of code that retrieves a `User` from the Database, > > performs > > some validation on it & then attempts to create another DB object called > > `StoredCookie` if that validation passes. So imagine something like: > > > > > > > > Now I'm having two separate troubles depending how I do things. > > > > The first issue is that the User object u is being detached after the > call > > to findByEmail. The customer property of user is defined using a > FetchTYpe > > of LAZY & I believe this combined with my use of > > TransactionAttributeType.REQUIRED at class level on my DAO's, is what is > > causing the entity to come back detached. So I've got over this hurdle > by > > adding a TransactionAttributeType of NEVER to any find methods. This > seems > > to leave the user object detached. Although this is what I want, I don't > > think I'm doing things right as it's probably causing issue #2. > > > > The second issue comes about when I call storedCookieDAO.persist(...). > It > > gives me a message saying that "The given instance > > "com.oobjects.sso.model.User-252" is not managed by this context". The > > user > > is still attached to something, as I can fetch lazily fetched properties. > > But as the UserDAO & StoredCookieDAO shared an entity manager (checked > the > > hash codes to make sure they are the same), I'm a little confused as to > > what > > they are attached to. > > > > Does anyone know what I'd need to do allow my StoredCookie to be > persisted? > > What is the User object attached to that's preventing it being persisted > by > > another DAO using the same entity manager? > > > > Here are a few code samples of how I am attempting various bits: > > https://gist.github.com/LTheobald/6248694 > > <https://gist.github.com/LTheobald/6248694> > > > > Thanks for any help anyone can give, > > Lee > > > > > > > > -- > > View this message in context: > > > http://openejb.979440.n4.nabble.com/Java-EE-transactions-lazy-loading-tp4664670.html > > Sent from the OpenEJB User mailing list archive at Nabble.com. > > >
