Hi JuneG,

There's nothing obviously wrong in your example. Can you run with SQL tracing on and see if there is a difference between when it works and when it doesn't?

Craig

On Dec 4, 2007, at 3:00 PM, JuneG wrote:




Craig L Russell wrote:

Hi,

I can't tell from your description what might be going wrong, but
there is one clue. You ask if all entities should be persisted in one
transaction. Not necessarily. But if you have several transactions,
it's possible that you are using detached instances and the problem
might be that if you assign an instance to a field of a detached
instance and then commit the transaction, nothing happens!

You need to make sure you merge all detached instances or nothing is
supposed to happen.

Can you attach a test case?

Craig



Thanks for your reply!

here is a simple version of what we are doing. we are creating all new
objects and then persist them in one transaction by a session bean.
occasionally A&C got stored without B. if we re run the process all A, B
and C will be saved.  what might be wrong?

@Entity
public class ClassA {

        //fields definition

@OneToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER, mappedBy
= "classA")
        private Collection<ClassB> classBs = new HashSet<ClassB>();

@OneToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER, mappedBy
= "classA)
        private Collection<classC> classCs = new HashSet<ClassC>();
}

@Entity
public class ClassB{

        @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
        @JoinColumn(name = "class_a_id")
        private ClassA classA;
        
        //fields defintions
}

@Entity
public class ClassC{

        @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
        @JoinColumn(name = "class_a_id")
        private ClassA classA;
        
        //fields defintions
}


//by default all the methods in this session bean has required tx attribute
@Stateless
public class SessionBean{

        @PersistenceContext(unitName = "test")
        private EntityManager em;

        public buildA{
                ClassA a = new ClassA();
                
                ClassB b = new ClassB();
                Collection<ClassB> classBs = new ArrayList<ClassB>();
                b.setClassA(a);
                classBs.add(a);
                a.setClassBs(classBs);
                
                ClassC c = new ClassC();
                Collection<ClassC> classCs = new ArrayList<ClassC>();
                c.setClassA(a);
                classCs.add(a);
                a.setClassCs(classCs);
                
                em.persist(a);
        }
}

--
View this message in context: http://www.nabble.com/Casade-Persist- tf4946103.html#a14161450
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:[EMAIL PROTECTED]
P.S. A good JDO? O, Gasp!

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to