OpenJPA
  1. OpenJPA
  2. OPENJPA-1226

Can not merge entity with nested embeddable

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2.3, 2.0.0-M3
    • Component/s: kernel
    • Labels:
      None

      Description

      When an entity has nested embeddables, the merge operation fails with the following exception:

      org.apache.openjpa.persistence.ArgumentException:
      Cannot manipulate identity of type "com.ibm.wssvt.acme.annuity.common.bean.jpa.Address": it's identity type is unknown.
      at org.apache.openjpa.kernel.StateManagerImpl.<init>(StateManagerImpl.java:173)
      at org.apache.openjpa.kernel.BrokerImpl.embed(BrokerImpl.java:2770)
      at org.apache.openjpa.kernel.DetachedStateManager.attach(DetachedStateManager.java:106)
      at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:251)
      at org.apache.openjpa.kernel.DetachedStateManager.attach(DetachedStateManager.java:244)
      at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:251)
      at org.apache.openjpa.kernel.AttachStrategy.attachMap(AttachStrategy.java:462)
      at org.apache.openjpa.kernel.DetachedStateManager.attach(DetachedStateManager.java:269)
      at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:251)
      at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:104)
      at org.apache.openjpa.kernel.BrokerImpl.attach(BrokerImpl.java:3346)
      at org.apache.openjpa.kernel.DelegatingBroker.attach(DelegatingBroker.java:1176)
      at org.apache.openjpa.persistence.EntityManagerImpl.merge(EntityManagerImpl.java:852)

        Activity

        Fay Wang created issue -
        Fay Wang made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Fay Wang made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Donald Woods made changes -
        Fix Version/s 2.0.0-M3 [ 12314148 ]
        Fix Version/s 2.0.0 [ 12314019 ]
        Hide
        Mateusz User added a comment - - edited

        In openJPA-1.2.1 version it still exist:
        setters are omitted..

        @Embeddable
        public class Address
        {
        private String street;

        private String homeNr;

        private String placeNr;

        private String city;

        private String zip;

        @Column(name = "street")
        public String getStreet()

        { return street; }

        @Column(name = "home_nr")
        public String getHomeNr()

        { return homeNr; }

        @Column(name = "place_nr")
        public String getPlaceNr()

        { return placeNr; }

        @Column(name = "city")
        public String getCity()

        { return city; }

        @Column(name = "zip")
        public String getZip()

        { return zip; }

        }

        @Embeddable
        public class Invoice
        {
        private String name;
        private Address address = new Address();
        private String nip;

        @Column(name = "invoice_name")
        public String getName()

        { return name; }

        @Embedded
        @AttributeOverrides(

        { @AttributeOverride(name = "street", column = @Column(name = "invoice_address_street")), @AttributeOverride(name = "homeNr", column = @Column(name = "invoice_address_home_nr")), @AttributeOverride(name = "placeNr", column = @Column(name = "invoice_address_place_nr")), @AttributeOverride(name = "city", column = @Column(name = "invoice_address_city")), @AttributeOverride(name = "zip", column = @Column(name = "invoice_address_zip")) }

        )
        public Address getAddress()

        { return address; }

        @Column(name = "invoice_nip")
        public String getNip()

        { return nip; }

        }

        @Embeddable
        public class Modification
        {
        private Date createdAt;
        private Date updatedAt;

        @Temporal(TemporalType.TIMESTAMP)
        @Column(name = "created_at")
        public Date getCreatedAt()

        { return createdAt; }

        @Temporal(TemporalType.TIMESTAMP)
        @Column(name = "updated_at")
        public Date getUpdatedAt()

        { return updatedAt; }

        public static Modification currentDate()

        { Modification result = new Modification(); Date date = new Date(); result.setCreatedAt(date); result.setUpdatedAt(date); return result; }

        }

        @MappedSuperclass
        public abstract class BaseID
        {
        private Integer id;
        private Integer flag;
        private Modification modification;

        @Id
        @GeneratedValue(strategy=GenerationType.IDENTITY)
        @Column(name = "id")
        public Integer getId()

        { return id; }

        @Column(name = "flag")
        public Integer getFlag()

        { return flag; }

        @Embedded
        public Modification getModification()

        { return modification; }

        }

        @Entity
        @Table(name = "offline_app_users_payment")
        public class OfflineUserPayment extends BaseID
        {
        private Date paymentDate;
        private Users user;
        private Payment payment;
        private Integer status;
        private String transaction;
        private Invoice invoice;

        @Temporal(TemporalType.TIMESTAMP)
        @Column(name = "payment_date")
        public Date getPaymentDate()

        { return paymentDate; }

        @ManyToOne(fetch=FetchType.LAZY)
        @JoinColumn(name="user_id")
        public Users getUser()

        { return user; }

        @ManyToOne(fetch=FetchType.LAZY)
        @JoinColumn(name="payment_id")
        public Payment getPayment()

        { return payment; }

        @Column(name = "status")
        public Integer getStatus()

        { return status; }

        @Column(name = "transaction_id")
        public String getTransaction()

        { return transaction; }

        @Embedded
        public Invoice getInvoice()

        { return invoice; }

        }
        Using merge on new object (should generate database insert):
        OfflineUserPayment newUserPayment = new OfflineUserPayment();
        newUserPayment.setFlag(1);
        newUserPayment.setModification(Modification.currentDate());
        newUserPayment.setPayment(payment);
        newUserPayment.setPaymentDate(null);
        newUserPayment.setStatus(-1);
        newUserPayment.setUser(user);
        Invoice invoice = new Invoice();
        invoice.setName(remoteInvoice.getName());
        invoice.setNip(remoteInvoice.getNip());
        invoice.getAddress().setStreet(remoteInvoice.getStreet());
        invoice.getAddress().setHomeNr(remoteInvoice.getHomeNr());
        invoice.getAddress().setPlaceNr(remoteInvoice.getPlaceNr());
        invoice.getAddress().setCity(remoteInvoice.getCity());
        invoice.getAddress().setZip(remoteInvoice.getZip());
        newUserPayment.setInvoice(invoice);
        getEntityManager().merge(newUserPayment);

        ///Stacktrace:
        <openjpa-1.2.1-r752877:753278 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Cannot manipulate identity of type "com.net.recepty.webservice.server.domain.Address": it's identity type is unknown.
        at org.apache.openjpa.kernel.StateManagerImpl.<init>(StateManagerImpl.java:162)
        at org.apache.openjpa.kernel.BrokerImpl.embed(BrokerImpl.java:2653)
        at org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:93)
        at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:241)
        at org.apache.openjpa.kernel.AttachStrategy.attachField(AttachStrategy.java:202)
        at org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:153)
        at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:241)
        at org.apache.openjpa.kernel.AttachStrategy.attachField(AttachStrategy.java:202)
        at org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:153)
        at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:241)
        at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:101)
        at org.apache.openjpa.kernel.BrokerImpl.attach(BrokerImpl.java:3212)
        at org.apache.openjpa.kernel.DelegatingBroker.attach(DelegatingBroker.java:1158)
        at org.apache.openjpa.persistence.EntityManagerImpl.merge(EntityManagerImpl.java:769)

        Show
        Mateusz User added a comment - - edited In openJPA-1.2.1 version it still exist: setters are omitted.. @Embeddable public class Address { private String street; private String homeNr; private String placeNr; private String city; private String zip; @Column(name = "street") public String getStreet() { return street; } @Column(name = "home_nr") public String getHomeNr() { return homeNr; } @Column(name = "place_nr") public String getPlaceNr() { return placeNr; } @Column(name = "city") public String getCity() { return city; } @Column(name = "zip") public String getZip() { return zip; } } @Embeddable public class Invoice { private String name; private Address address = new Address(); private String nip; @Column(name = "invoice_name") public String getName() { return name; } @Embedded @AttributeOverrides( { @AttributeOverride(name = "street", column = @Column(name = "invoice_address_street")), @AttributeOverride(name = "homeNr", column = @Column(name = "invoice_address_home_nr")), @AttributeOverride(name = "placeNr", column = @Column(name = "invoice_address_place_nr")), @AttributeOverride(name = "city", column = @Column(name = "invoice_address_city")), @AttributeOverride(name = "zip", column = @Column(name = "invoice_address_zip")) } ) public Address getAddress() { return address; } @Column(name = "invoice_nip") public String getNip() { return nip; } } @Embeddable public class Modification { private Date createdAt; private Date updatedAt; @Temporal(TemporalType.TIMESTAMP) @Column(name = "created_at") public Date getCreatedAt() { return createdAt; } @Temporal(TemporalType.TIMESTAMP) @Column(name = "updated_at") public Date getUpdatedAt() { return updatedAt; } public static Modification currentDate() { Modification result = new Modification(); Date date = new Date(); result.setCreatedAt(date); result.setUpdatedAt(date); return result; } } @MappedSuperclass public abstract class BaseID { private Integer id; private Integer flag; private Modification modification; @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name = "id") public Integer getId() { return id; } @Column(name = "flag") public Integer getFlag() { return flag; } @Embedded public Modification getModification() { return modification; } } @Entity @Table(name = "offline_app_users_payment") public class OfflineUserPayment extends BaseID { private Date paymentDate; private Users user; private Payment payment; private Integer status; private String transaction; private Invoice invoice; @Temporal(TemporalType.TIMESTAMP) @Column(name = "payment_date") public Date getPaymentDate() { return paymentDate; } @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="user_id") public Users getUser() { return user; } @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="payment_id") public Payment getPayment() { return payment; } @Column(name = "status") public Integer getStatus() { return status; } @Column(name = "transaction_id") public String getTransaction() { return transaction; } @Embedded public Invoice getInvoice() { return invoice; } } Using merge on new object (should generate database insert): OfflineUserPayment newUserPayment = new OfflineUserPayment(); newUserPayment.setFlag(1); newUserPayment.setModification(Modification.currentDate()); newUserPayment.setPayment(payment); newUserPayment.setPaymentDate(null); newUserPayment.setStatus(-1); newUserPayment.setUser(user); Invoice invoice = new Invoice(); invoice.setName(remoteInvoice.getName()); invoice.setNip(remoteInvoice.getNip()); invoice.getAddress().setStreet(remoteInvoice.getStreet()); invoice.getAddress().setHomeNr(remoteInvoice.getHomeNr()); invoice.getAddress().setPlaceNr(remoteInvoice.getPlaceNr()); invoice.getAddress().setCity(remoteInvoice.getCity()); invoice.getAddress().setZip(remoteInvoice.getZip()); newUserPayment.setInvoice(invoice); getEntityManager().merge(newUserPayment); ///Stacktrace: <openjpa-1.2.1-r752877:753278 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Cannot manipulate identity of type "com.net.recepty.webservice.server.domain.Address": it's identity type is unknown. at org.apache.openjpa.kernel.StateManagerImpl.<init>(StateManagerImpl.java:162) at org.apache.openjpa.kernel.BrokerImpl.embed(BrokerImpl.java:2653) at org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:93) at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:241) at org.apache.openjpa.kernel.AttachStrategy.attachField(AttachStrategy.java:202) at org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:153) at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:241) at org.apache.openjpa.kernel.AttachStrategy.attachField(AttachStrategy.java:202) at org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:153) at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:241) at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:101) at org.apache.openjpa.kernel.BrokerImpl.attach(BrokerImpl.java:3212) at org.apache.openjpa.kernel.DelegatingBroker.attach(DelegatingBroker.java:1158) at org.apache.openjpa.persistence.EntityManagerImpl.merge(EntityManagerImpl.java:769)
        Jeremy Bauer made changes -
        Resolution Fixed [ 1 ]
        Status Closed [ 6 ] Reopened [ 4 ]
        Jeremy Bauer made changes -
        Fix Version/s 1.2.3 [ 12314517 ]
        Jeremy Bauer made changes -
        Status Reopened [ 4 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        2h 46m 1 Fay Wang 05/Aug/09 03:58
        Resolved Resolved Closed Closed
        7s 1 Fay Wang 05/Aug/09 03:59
        Closed Closed Reopened Reopened
        1344d 16h 58m 1 Jeremy Bauer 10/Apr/13 20:57
        Reopened Reopened Resolved Resolved
        21s 1 Jeremy Bauer 10/Apr/13 20:57

          People

          • Assignee:
            Unassigned
            Reporter:
            Fay Wang
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development