You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Andrei Bratu (JIRA)" <ji...@apache.org> on 2012/04/27 14:59:50 UTC

[jira] [Created] (OPENJPA-2181) Persisting an Entity containing a Collection of Interfaces

Andrei Bratu created OPENJPA-2181:
-------------------------------------

             Summary: Persisting an Entity containing a Collection of Interfaces
                 Key: OPENJPA-2181
                 URL: https://issues.apache.org/jira/browse/OPENJPA-2181
             Project: OpenJPA
          Issue Type: Bug
    Affects Versions: 2.2.0, 2.1.1
            Reporter: Andrei Bratu


I have an Interface (IInterface) and 2 classes that implements that interface (IInterface). Also in another class ( Holder ) I have a collection of interface items ( Collection<IInterface> ). 

When I try to execute the code from OpenJPA_Test.main, in my associated table ( holder_classes), the column which is supposed to hold the references to Class1 or Class2 objects are NULL. 

public class OpenJPA_Test { 

    private static HolderDao holderDao = EntityDaoFactory.inst().getHolderDao(); 
    
    /** 
     * @param args the command line arguments 
     */ 
    public static void main(String[] args) { 
        // TODO code application logic here 
        Holder h = new Holder(); 
        LinkedList<IInterface> list = new LinkedList<IInterface>(); 
        
        Class1 c1 = new Class1(); 
        Class2 c2 = new Class2(); 
        
        list.add(c1); 
        list.add(c2); 
        
        h.setClasses(list); 
        holderDao.create(h); 
        
    } 
} 



--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (OPENJPA-2181) Cascading a persist to a collection of Entities that use IDENTITY generation strategy fails.

Posted by "Rick Curtis (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-2181?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13263688#comment-13263688 ] 

Rick Curtis commented on OPENJPA-2181:
--------------------------------------

Attaching more details from the users mailing list....

There are two workarounds:

Option #1 -- you could change your ID generation strategy to AUTO[1]. 

Option #2 -- don't rely on the cascade persist functionality. Manually persist each of your children objects (Class1, Class2) before persisting Holder[2].

[1]    
@Id
@GeneratedValue(strategy = GenerationType.AUTO)

[2]
class HolderDao ....
    public boolean create(Holder h) {
        EntityTransaction trans = em.getTransaction();

        trans.begin();

        for (IInterface i : h.getClasses()) {
            em.persist(i);
        }
        em.persist(h);
        trans.commit();

        return true;
                
> Cascading a persist to a collection of Entities that use IDENTITY generation strategy fails.
> --------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2181
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2181
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 2.1.1, 2.2.0
>            Reporter: Andrei Bratu
>              Labels: IDENTITY, OneToMany, cascade, persist, strategy
>         Attachments: src.rar
>
>
> I have an Interface (IInterface) and 2 classes that implements that interface (IInterface). Also in another class ( Holder ) I have a collection of interface items ( Collection<IInterface> ). 
> When I try to execute the code from OpenJPA_Test.main, in my associated table ( holder_classes), the column which is supposed to hold the references to Class1 or Class2 objects are NULL. 
> public class OpenJPA_Test { 
>     private static HolderDao holderDao = EntityDaoFactory.inst().getHolderDao(); 
>     
>     /** 
>      * @param args the command line arguments 
>      */ 
>     public static void main(String[] args) { 
>         // TODO code application logic here 
>         Holder h = new Holder(); 
>         LinkedList<IInterface> list = new LinkedList<IInterface>(); 
>         
>         Class1 c1 = new Class1(); 
>         Class2 c2 = new Class2(); 
>         
>         list.add(c1); 
>         list.add(c2); 
>         
>         h.setClasses(list); 
>         holderDao.create(h); 
>         
>     } 
> } 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (OPENJPA-2181) Cascading a persist to a collection of Entities that use IDENTITY generation strategy fails.

Posted by "Rick Curtis (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-2181?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Rick Curtis updated OPENJPA-2181:
---------------------------------

     Labels: IDENTITY OneToMany cascade persist strategy  (was: )
    Summary: Cascading a persist to a collection of Entities that use IDENTITY generation strategy fails.  (was: Persisting an Entity containing a Collection of Interfaces)

Updating description
                
> Cascading a persist to a collection of Entities that use IDENTITY generation strategy fails.
> --------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2181
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2181
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 2.1.1, 2.2.0
>            Reporter: Andrei Bratu
>              Labels: IDENTITY, OneToMany, cascade, persist, strategy
>         Attachments: src.rar
>
>
> I have an Interface (IInterface) and 2 classes that implements that interface (IInterface). Also in another class ( Holder ) I have a collection of interface items ( Collection<IInterface> ). 
> When I try to execute the code from OpenJPA_Test.main, in my associated table ( holder_classes), the column which is supposed to hold the references to Class1 or Class2 objects are NULL. 
> public class OpenJPA_Test { 
>     private static HolderDao holderDao = EntityDaoFactory.inst().getHolderDao(); 
>     
>     /** 
>      * @param args the command line arguments 
>      */ 
>     public static void main(String[] args) { 
>         // TODO code application logic here 
>         Holder h = new Holder(); 
>         LinkedList<IInterface> list = new LinkedList<IInterface>(); 
>         
>         Class1 c1 = new Class1(); 
>         Class2 c2 = new Class2(); 
>         
>         list.add(c1); 
>         list.add(c2); 
>         
>         h.setClasses(list); 
>         holderDao.create(h); 
>         
>     } 
> } 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (OPENJPA-2181) Persisting an Entity containing a Collection of Interfaces

Posted by "Andrei Bratu (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-2181?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andrei Bratu updated OPENJPA-2181:
----------------------------------

    Attachment: src.rar

Added the Unit Test
                
> Persisting an Entity containing a Collection of Interfaces
> ----------------------------------------------------------
>
>                 Key: OPENJPA-2181
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2181
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 2.1.1, 2.2.0
>            Reporter: Andrei Bratu
>         Attachments: src.rar
>
>
> I have an Interface (IInterface) and 2 classes that implements that interface (IInterface). Also in another class ( Holder ) I have a collection of interface items ( Collection<IInterface> ). 
> When I try to execute the code from OpenJPA_Test.main, in my associated table ( holder_classes), the column which is supposed to hold the references to Class1 or Class2 objects are NULL. 
> public class OpenJPA_Test { 
>     private static HolderDao holderDao = EntityDaoFactory.inst().getHolderDao(); 
>     
>     /** 
>      * @param args the command line arguments 
>      */ 
>     public static void main(String[] args) { 
>         // TODO code application logic here 
>         Holder h = new Holder(); 
>         LinkedList<IInterface> list = new LinkedList<IInterface>(); 
>         
>         Class1 c1 = new Class1(); 
>         Class2 c2 = new Class2(); 
>         
>         list.add(c1); 
>         list.add(c2); 
>         
>         h.setClasses(list); 
>         holderDao.create(h); 
>         
>     } 
> } 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira