[ 
https://issues.apache.org/jira/browse/OPENJPA-2519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14073242#comment-14073242
 ] 

Marc Logemann edited comment on OPENJPA-2519 at 7/24/14 2:43 PM:
-----------------------------------------------------------------

Sure: 

i use DAO layer to get entities to my service layer. Transaction ends in DAO 
layer and so i get a detached instance. The one-to-one relationsship is filled 
in DB but "null" in current context because it was not loaded (lazy). Now i 
attach a different object to the 1:1 relation and try to persist it. Persist 
means, i have this in my DAO:

{code:java}
 public void saveMetaData(Object metaData) {
        OpenJPAEntityManager oem = OpenJPAPersistence.cast(em);
        if (oem.isDetached(metaData)) {
            em.merge(metaData);
        } else {
            em.persist(metaData);
        }
    }
{code}

persistence.xml looks like this (i am using spring, so i dont mention entities 
there)

{code:xml}
<persistence xmlns="http://java.sun.com/xml/ns/persistence";
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd";
             version="1.0">
    <persistence-unit name="punit">
        
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
        <properties>
            <property name="openjpa.Log" value="log4j"/>
            <property name="openjpa.jdbc.DBDictionary" value="mysql"/>
            <property name="openjpa.ConnectionProperties"
                      value="DriverClassName=com.mysql.jdbc.Driver,
                              Url=jdbc:mysql://localhost/Netversys2,
                              Username=netversys,
                              Password=sysjava"/>
        </properties>
    </persistence-unit>
</persistence>
{code}



was (Author: logemann):
Sure: 

i use DAO layer to get entities to my service layer. Transaction ends in DAO 
layer and so i get a detached instance. The one-to-one relationsship is filled 
in DB but "null" in current context because it was not loaded (lazy). Now i 
attach a different object to the 1:1 relation and try to persist it. Persist 
means, i have this in my DAO:

 public void saveMetaData(Object metaData) {
        OpenJPAEntityManager oem = OpenJPAPersistence.cast(em);
        if (oem.isDetached(metaData)) {
            em.merge(metaData);
        } else {
            em.persist(metaData);
        }
    }

persistence.xml looks like this (i am using spring, so i dont mention entities 
there)

{code:xml}
<persistence xmlns="http://java.sun.com/xml/ns/persistence";
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd";
             version="1.0">
    <persistence-unit name="punit">
        
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
        <properties>
            <property name="openjpa.Log" value="log4j"/>
            <property name="openjpa.jdbc.DBDictionary" value="mysql"/>
            <property name="openjpa.ConnectionProperties"
                      value="DriverClassName=com.mysql.jdbc.Driver,
                              Url=jdbc:mysql://localhost/Netversys2,
                              Username=netversys,
                              Password=sysjava"/>
        </properties>
    </persistence-unit>
</persistence>
{code}


> fetchType.lazy and persisting one-to-one relations
> --------------------------------------------------
>
>                 Key: OPENJPA-2519
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2519
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 2.2.0
>            Reporter: Marc Logemann
>
> Hi,
> i have an entity which has a mapped superclass. In that superclass i have a 
> 1:1 relation which is marked "lazy". 
> Now when i load that entity, attach an object to that relation and persist 
> it, the change is not reflected in the database. But the jpaversion is 
> increased. Also all other "normal" mapped fields are persisted but not the 
> Lazy 1:1. Of course i checked the object right before persist and it looks 
> pretty perfect. 
> If i remove the lazy attribute from the annotation. Everything works like 
> expected. When looking at OPENJPA-2505 and this issue, i am really concerned 
> about your FetchType implementation. This definitely feels buggy.
> And to make things more weird: On my MySQL box, the bug is non-existant. As 
> soon as i deploy the application (really the very same application) to 
> MariaDB, its there.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to