Sorry for the annoyment, I found an error in my code so ignore the mail
below.

I'll keep you inform when it's fixed.

Christophe
 

-----Original Message-----
From: Christophe Thiebaud [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, February 12, 2008 1:45 AM
To: [email protected]
Cc: Louis Lecaroz
Subject: RE: [appfuse-user] Appfuse 2.01 + extended persistence context

Unfortunately, the issue is not closed. 

Here is what I try to do (a web service is servicing the requests)

There are two entities, entity 'parent' and entity 'child' with a 1 to N
relationship.

httpRequest #1 with some parameters
------
Create a new entity 'parent' instance from parameters Save in DB through
the entityManager.
Create a new entity 'child' instance from parameters Set
'child'.'parent' attribute to entity 'parent' 
Save in DB through the entityManager.
Put entity 'parent' returned by the entityManager into a httpSession
attribute

-> everything's fine.

httpRequest #2, same httpSession
------
Get entity 'parent' from httpSession attribute Create a new entity
'child' from parameters Set 'child'.'parent' attribute to entity
'parent' retrieved from httpSession Save entity 'child' through the
entityManager.

-> Exception!
WARN | SQL Error: 1062, SQLState: 23000
ERROR | Duplicate entry '65538-262144-1' for key 2 ERROR | Could not
synchronize database state with session 

I believe the entityManager is trying to insert not only the child but
the parent as well and fails on the unique key.

How can explain to the entityManager that I do not want or insert nor
update the parent entity ?

Fetching again the parent entity from the DB on request #2 is not an
option as we have performance constraints.
I had hoped the entityManager would act as a cache and help us to remove
some communication with the DB.

The whole thing is trivial using JDBC. I'd hate to fall back on a JDBC
implementation.

Has anybody tried to do similar things ? 

Christophe
 

-----Original Message-----
From: Christophe Thiebaud [mailto:[EMAIL PROTECTED]
Sent: Monday, February 11, 2008 7:53 AM
To: [email protected]
Subject: RE: [appfuse-user] Appfuse 2.01 + extended persistence context

Thanks, this should close the issue.  
Christophe

-----Original Message-----
From: Matt Raible [mailto:[EMAIL PROTECTED]
Sent: Monday, February 11, 2008 4:35 AM
To: [email protected]
Subject: Re: [appfuse-user] Appfuse 2.01 + extended persistence context

All the persistence frameworks in AppFuse allow a entity to be
"detached" and then re-attached later. Transactions are demarcated at
the service layer - so they're already detached (in a sense) when you
edit them in a form. You should be able to stuff the entity in the
session, operate it on it over a page or 2 and then save it again. As
long as the primary key is carried through, an update should occur
instead of an insert. If that doesn't work, I'd look at SWF. It might be
overkill, but it is powerful and it's a tool worth having in your tool
belt.

Matt

On 2/10/08, Christophe Thiebaud <[EMAIL PROTECTED]> wrote:
> That's close to what I meant. I was investigating Spring WebFlow that 
> I see is an alternative to MyFaces Orchestra. But although I am sure 
> these tools have the solution to my problem, I feel that they are
overkill.
>
> Sorry, but my understanding of the spring/jpa/transactions usage in 
> general and in AppFuse in particular is not very good.
>
> I guess my problem boils down to:
> If I fetch an entity from the DB during the processing of a request, 
> how can I re-use this entity in subsequent requests ? Can I merely 
> store it as a session attribute ? But isn't this entity bound to a 
> persistence context that lives only within a transaction, so within a 
> request ? So after reading the jpa doc it looks that I need an 
> extended persistence context that lives across transactions. But I 
> have no clue on how implementing that in AppFuse. Or maybe it is the 
> default case in AppFuse ?
>
> thanks
> Christophe
>
>
> -----Original Message-----
> From: Matt Raible [mailto:[EMAIL PROTECTED]
> Sent: Monday, February 11, 2008 2:00 AM
> To: [email protected]
> Subject: Re: [appfuse-user] Appfuse 2.01 + extended persistence 
> context
>
> What do you mean by "extended persistence context" - do you have an 
> example? Do you mean something like MyFaces Orchestra?
>
> http://myfaces.apache.org/orchestra/index.html
>
> Matt
>
> On 2/10/08, Christophe Thiebaud <[EMAIL PROTECTED]> wrote:
> > Hi all,
> >
> > We are happy users of AppFuse 2.0.1, struts2 + jpa flavor. BTW, 
> > thanks
>
> > Matt for the good work.
> >
> > I need to implement an extended persitence context.
> > I am lost in the wealth on general documentation on the subject.
> > I was not able to find in the appfuse user list any thread on this 
> > subject.
> >
> > Can somebody gives us pointers decribing how to implement a jpa 
> > extended persistence context in AppFuse.
> > (Ideally a sample application) ?
> >
> > thanks
> > Christophe
> >
> > --------------------------------------------------------------------
> > - To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to