I have read through the hibernate doc on how the persistence context is stored
and synchronized several times, but cannot find an answer. The main question
is this:
Can I persist a parent and its list of children in the same method?
i.e.
| public void persistParent(Parent p)
| {
| ParentEntityBean pBean = new ParentEntityBean(p);
| em.persist(pBean);
|
| List<Child> children = p.getChildren();
| Child firstChild = children.get(0);
| ChildEntityBean cBean = new ChildEntityBean(firstChild);
| em.persist(cBean);
|
| ParentChildRelationEntityBean pcRelBean = new
ParentChildRelationEntityBean(pBean,cBean);
| em.persist(pcRelBean);
|
| }
|
I have also tried flushing and refreshing (as talked about in the Hibernate
EntityManager docs).
i.e.
| public void persistParent(Parent p)
| {
| ...
| em.persist(pBean);
| em.flush();
| em.refresh(pBean);
|
| ...
| em.persist(cBean);
| em.flush();
| em.refresh(cBean);
|
| ...
| em.persist(pcRelBean);
| }
|
Finally, I've tried using my own transaction:
| public void persistParent(Parent p)
| {
| EntityManagerFactory emf =
Persistence.createEntityManagerFactory("mysqlUnit",new HashMap());
| EntityManager em = emf.createEntityManager();
| ...
| EntityTransaction t1 = em.getTransaction();
| t1.begin();
| em.persist(pBean);
| t1.commit();
|
| ...
| EntityTransaction t2 = em.getTransaction();
| t2.begin();
| em.persist(cBean);
| t2.commit();
|
| ...
| em.persist(pcRelBean);
| }
|
If you can help me solve this problem, I would be eternally grateful. I admit
I'm new new Hibernate, and maybe this is a trivial question, but I would really
appreciate any time that you have into figuring this out.
Thanks in advance!
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3942295#3942295
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3942295
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user