You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Kai Feng Zhang (JIRA)" <ji...@apache.org> on 2010/09/15 14:56:32 UTC

[jira] Created: (OPENJPA-1797) Can not persist subclass entity with its full data, if this subclass entity has ManyToOne to another entity

Can not persist subclass entity with its full data, if this subclass entity has ManyToOne to another entity
-----------------------------------------------------------------------------------------------------------

                 Key: OPENJPA-1797
                 URL: https://issues.apache.org/jira/browse/OPENJPA-1797
             Project: OpenJPA
          Issue Type: Bug
          Components: jpa
    Affects Versions: 2.0.1
            Reporter: Kai Feng Zhang


A Person entity class, which has such emails field:

@OneToMany(targetEntity = EmailDb.class, mappedBy = "person", cascade = CascadeType.ALL)
  protected List<ListField> emails = new ArrayList<ListField>();

While Email entity is subclass of @MappedSuperclass ListFieldDb.

Then I create email and add to person:

EmailDb email = new EmailDb();
email.setValue(targetAddress);
email.setPrimary(false);
email.setType("emailType");

person.addEmail(emial);
em.persist(person);

But what I see from console about email table changes is: INSERT INTO email (oid, person_id) VALUES (?, ?), and other data lost, especially the map key 'person_id' to person table.

Not sure if I am using something wrong? or this is a known issue?

I pasted source code files for entity relationship reference. Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1797) Can not persist subclass entity with its full data, if this subclass entity has ManyToOne to another entity

Posted by "Kai Feng Zhang (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1797?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12910423#action_12910423 ] 

Kai Feng Zhang commented on OPENJPA-1797:
-----------------------------------------

Thank you Pinaki.

I made a workaround to solve this issue, that is to remove @MappedSuperclass from ListFieldDb, and use @Inheritance(strategy=InheritanceType.JOINED) on ListFieldDb. Then I could store data of email into EmailDb and ListFieldDb.

But anyway this is a problem of @MappedSuperclass, which is subclass entity data can not be stored with integrity.

> Can not persist subclass entity with its full data, if this subclass entity has ManyToOne to another entity
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-1797
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1797
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 2.0.1
>            Reporter: Kai Feng Zhang
>         Attachments: EmailDb.java, ListFieldDb.java, PersonDb.java
>
>
> A Person entity class, which has such emails field:
> @OneToMany(targetEntity = EmailDb.class, mappedBy = "person", cascade = CascadeType.ALL)
>   protected List<ListField> emails = new ArrayList<ListField>();
> While Email entity is subclass of @MappedSuperclass ListFieldDb.
> Then I create email and add to person:
> EmailDb email = new EmailDb();
> email.setValue(targetAddress);
> email.setPrimary(false);
> email.setType("emailType");
> person.addEmail(emial);
> em.persist(person);
> But what I see from console about email table changes is: INSERT INTO email (oid, person_id) VALUES (?, ?), and other data lost, especially the map key 'person_id' to person table.
> Not sure if I am using something wrong? or this is a known issue?
> I pasted source code files for entity relationship reference. Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-1797) Can not persist subclass entity with its full data, if this subclass entity has ManyToOne to another entity

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

Kai Feng Zhang updated OPENJPA-1797:
------------------------------------

    Attachment: PersonDb.java
                EmailDb.java
                ListFieldDb.java

This only happens when I want to persist the subclass entity. If it's a no-superclass entity and has manytoone relation to person, then I can store all its data into table.

> Can not persist subclass entity with its full data, if this subclass entity has ManyToOne to another entity
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-1797
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1797
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 2.0.1
>            Reporter: Kai Feng Zhang
>         Attachments: EmailDb.java, ListFieldDb.java, PersonDb.java
>
>
> A Person entity class, which has such emails field:
> @OneToMany(targetEntity = EmailDb.class, mappedBy = "person", cascade = CascadeType.ALL)
>   protected List<ListField> emails = new ArrayList<ListField>();
> While Email entity is subclass of @MappedSuperclass ListFieldDb.
> Then I create email and add to person:
> EmailDb email = new EmailDb();
> email.setValue(targetAddress);
> email.setPrimary(false);
> email.setType("emailType");
> person.addEmail(emial);
> em.persist(person);
> But what I see from console about email table changes is: INSERT INTO email (oid, person_id) VALUES (?, ?), and other data lost, especially the map key 'person_id' to person table.
> Not sure if I am using something wrong? or this is a known issue?
> I pasted source code files for entity relationship reference. Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1797) Can not persist subclass entity with its full data, if this subclass entity has ManyToOne to another entity

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

Pinaki Poddar commented on OPENJPA-1797:
----------------------------------------

> protected List<ListField> emails = new ArrayList<ListField>(); 

ListField is an interface and ListFieldDB is the implementation. Try

    protected List<ListFieldDB> emails = new ArrayList<ListFieldDB>(); 




> Can not persist subclass entity with its full data, if this subclass entity has ManyToOne to another entity
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-1797
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1797
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 2.0.1
>            Reporter: Kai Feng Zhang
>         Attachments: EmailDb.java, ListFieldDb.java, PersonDb.java
>
>
> A Person entity class, which has such emails field:
> @OneToMany(targetEntity = EmailDb.class, mappedBy = "person", cascade = CascadeType.ALL)
>   protected List<ListField> emails = new ArrayList<ListField>();
> While Email entity is subclass of @MappedSuperclass ListFieldDb.
> Then I create email and add to person:
> EmailDb email = new EmailDb();
> email.setValue(targetAddress);
> email.setPrimary(false);
> email.setType("emailType");
> person.addEmail(emial);
> em.persist(person);
> But what I see from console about email table changes is: INSERT INTO email (oid, person_id) VALUES (?, ?), and other data lost, especially the map key 'person_id' to person table.
> Not sure if I am using something wrong? or this is a known issue?
> I pasted source code files for entity relationship reference. Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.