Mantis - Resin
Viewing Issue Advanced Details
2599 minor always 04-14-08 06:09 04-14-08 13:30
tsv  
ferg  
normal  
closed 3.1.5  
fixed  
none    
none 3.1.6  
0002599: Amber not persisting child enties properly
My setup is resin 3.1.5 with mysql database for persistence.

I have a parent entity containing unidirectional child entity.

When i persist the parent, the child does get persisted aswell, but the parent never gets the child ID and thus it is lost.

private void test() {
        Parent p = new Parent();
        
        Child c = new Child();
        c.setName("Elizabeth");
        
        p.setChild(c);
        
        EntityTransaction tx = _manager.getTransaction();
        try {
            tx.begin();
                _manager.persist(p);
            tx.commit();
               
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
        }
        
        System.out.println("Parent: " + p.getId());
        System.out.println("Child : " + p.getChild().getId());
    }

Running the above test yields:

Parent: 1
Child : 1

But in the parent table in the database:
ID Child
1 0


Source attached
 Parent.java [^] (654 bytes) 04-14-08 06:09
 Child.java [^] (442 bytes) 04-14-08 06:09

Notes
(0002971)
ferg   
04-14-08 13:30   
jpa/0o5{0,1}