I am using openjpa1.0. My main entity class is RecPolicy which has a
@OneToMany relation to entity 'CallLog'. I am using 'LAZY' fetch and
'ALL' for cascade.  See corresponding field 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?

 

Reply via email to