openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ajay Aggarwal" <aaggar...@covergence.com>
Subject RE: OneToMany - related entry not getting persisted?
Date Mon, 29 Oct 2007 19:48:47 GMT
I am using "Field" Access type. I will have to learn Enhancer to give
you the answer to your last question. Meanwhile here are the openjpa
configuration properties I am using in persistence.xml

<persistence-unit name="covApiService"
transaction-type="RESOURCE_LOCAL">
		<provider> 
	
org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
	
<class>com.covergence.soa.covapi.recpolicy.RecPolicy</class>
	
<class>com.covergence.soa.covapi.recpolicy.CallLog</class>
		<properties>
			<property name="openjpa.ConnectionURL" 
	
value="jdbc:postgresql://localhost:5432/wlDemo"/>
			<property name="openjpa.ConnectionDriverName" 
				value="org.postgresql.Driver"/>
			<property name="openjpa.ConnectionUserName"
value="xxx"/>
			<property name="openjpa.ConnectionPassword"
value="xxx"/>
			<property
name="openjpa.jdbc.SynchronizeMappings" value="refresh"/>
			<property name="openjpa.Log" 
				value="File=stdout, DefaultLevel=WARN,
Runtime=INFO, Tool=INFO, SQL=TRACE"/>
		</properties>
	</persistence-unit>

-----Original Message-----
From: Patrick Linskey [mailto:plinskey@gmail.com] 
Sent: Monday, October 29, 2007 3:07 PM
To: users@openjpa.apache.org
Subject: Re: OneToMany - related entry not getting persisted?

> Yes, let me know what additional information you would need to
reproduce
> this. It's a pretty straight forward test case.

Ideally, the actual sources.

In the absence of the source code:

- what access type are you using?
- what are all your OpenJPA configuration options set to?
- does this happen if you do run the OpenJPA enhancer?

-Patrick

On 10/29/07, Ajay Aggarwal <aaggarwal@covergence.com> wrote:
> Yes, let me know what additional information you would need to
reproduce
> this. It's a pretty straight forward test case.
>
> I have two entity beans A and B
> A has OneToMany relationship to B with persist=ALL, fetch=LAZY
> There is no inverse relation from B to A.
> I am using it inside servlets (inside WebSphere Application Server
6.1)
> Now inside a transaction
>   - I find an instance of A using entity manager
>   - I get the list of 'B' from this instance of A and add a new
instance
> of B to this list
>   - I commit this transaction
>
> The new instance of B does not get added.
>
> However if I change fetch=EAGER for this relation, things work fine
and
> new instance of B above gets inserted.
>
> One more piece of information. I am not using OpenJPA enhancer and
when
> I deploy my application with fetch=LAZY I see this log/error. Note: In
> my actual application RecPolicy has OneToMany relation to CallLog.
>
> [10/25/07 12:45:22:129 EDT] 00000024 SystemErr     R 5517137
> covApiService  INFO   [WebContainer : 2] openjpa.Enhance - Creating
> subclass and redefining methods for "[class
> com.covergence.soa.covapi.recpolicy.CallLog, class
> com.covergence.soa.covapi.recpolicy.RecPolicy]". This means that your
> application will be less efficient than it would if you ran the
OpenJPA
> enhancer.
>
> -----Original Message-----
> From: Patrick Linskey [mailto:plinskey@gmail.com]
> Sent: Monday, October 29, 2007 1:18 PM
> To: users@openjpa.apache.org
> Subject: Re: OneToMany - related entry not getting persisted?
>
> Hi,
>
> Given that it's a one-sided OneToMany, it sounds like it might be a
> bug. Is it possible for you to provide us with more information, or
> even a test case that fails?
>
> Thanks,
>
> -Patrick
>
> On 10/26/07, Ajay Aggarwal <aaggarwal@covergence.com> wrote:
> > If I use FetchType.EAGER for my @OneToMany relation, things work
fine
> > and I correctly see following SQL statements in the trace log
> >   - INSERT for new row into 'callLog'
> >   - UPDATE for 'recPolicy'
> >   - INSERT for a new row into association table 'recPolicy_callLog'
> >
> > So the question remains why is this not working for FetchType.LAZY?
Is
> > this a bug in openJPA 1.0 or incorrect-usage / user-error on my
part?
> >
> >
> > -----Original Message-----
> > From: Ajay Aggarwal [mailto:aaggarwal@covergence.com]
> > Sent: Friday, October 26, 2007 1:39 PM
> > To: users@openjpa.apache.org
> > Subject: RE: OneToMany - related entry not getting persisted?
> >
> > Thanks. But in my case, I do not have a ManyToOne relation on the
> other
> > side and that's on purpose.
> >
> > -----Original Message-----
> > From: Gul Onural [mailto:onural@nortel.com]
> > Sent: Friday, October 26, 2007 1:30 PM
> > To: users@openjpa.apache.org
> > Subject: RE: OneToMany - related entry not getting persisted?
> >
> >
> >
> > Have you checked
> > http://forums.java.net/jive/message.jspa?messageID=212597.
> >
> > I believe that will answer your question.
> >
> > Gul
> >
> > -----Original Message-----
> > From: Ajay Aggarwal [mailto:aaggarwal@covergence.com]
> > Sent: Friday, October 26, 2007 1:19 PM
> > To: users@openjpa.apache.org
> > Subject: OneToMany - related entry not getting persisted?
> >
> > I am using openjpa1.0. My main entity class is RecPolicy which has a
> > @OneToMany relation to entity 'CallLog'. I am using FetchType.LAZY
> and
> > CascadeType.ALL. See below:
> >
> >
> >
> >         Public class RecPolicy {
> >
> >             ...
> >
> >             @OneToMany (fetch=FetchType.LAZY,
cascade=CascadeType.ALL)
> >
> >             private List <CallLog> calls;
> >
> >        }
> >
> >
> >
> >
> >
> > Now I am trying to add a CallLog entry to an existing RecPolicy
entry,
> > but it's not working. My code looks like
> >
> >
> >
> >                         EntityManager em =
> > factory.createEntityManager();
> >
> >                         EntityTransaction tx = em.getTransaction();
> >
> >                         try {
> >
> >                                     tx.begin();
> >
> >                                     RecPolicy.RecPolicyId policyId =
> ...
> >
> >                                     RecPolicy policy =
> > em.find(RecPolicy.class, policyId);
> >
> >                                     CallLog callLog = new
CallLog(sid,
> > this.fromUri, this.toUri);
> >
> >                                     policy.calls.add(callLog);
> >
> >                                     tx.commit();
> >
> >                         } catch (Exception e) {
> >
> >                                     if (tx.isActive())
tx.rollback();
> >
> >                         } finally {
> >
> >                                     em.close();
> >
> >                         }
> >
> >
> >
> >
> >
> > When I enable openjpa logging all I see is an UPDATE sql to update
the
> > RecPolicy, but no INSERT for CallLog? Do I need to persist new
CallLog
> > above explicitly? Is 'LAZY' fetch causing this behavior?
> >
> >
> >
> >
>
>
> --
> Patrick Linskey
> 202 669 5907
>


-- 
Patrick Linskey
202 669 5907

Mime
View raw message