You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by fa...@apache.org on 2009/07/29 14:09:16 UTC
svn commit: r798868 - in /openjpa/trunk:
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/
Author: faywang
Date: Wed Jul 29 12:09:16 2009
New Revision: 798868
URL: http://svn.apache.org/viewvc?rev=798868&view=rev
Log:
OPENJPA-1204: fix enum evaluation in EmbeddedId
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/BeneContact.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/BeneContactId.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Beneficiary.java (with props)
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedValueHandler.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMappedById.java
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedValueHandler.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedValueHandler.java?rev=798868&r1=798867&r2=798868&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedValueHandler.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedValueHandler.java Wed Jul 29 12:09:16 2009
@@ -247,8 +247,11 @@
embed.loadEmbedded(em, store, fetch, cval);
else {
if (!(em instanceof ObjectIdStateManager))
- cval = embed.toEmbeddedObjectValue(cval);
- em.store(fms[i].getIndex(), cval);
+ cval = embed.toEmbeddedObjectValue(cval);
+ if (fms[i].getHandler() != null)
+ cval = fms[i].getHandler().toObjectValue(fms[i], cval);
+
+ em.store(fms[i].getIndex(), cval);
}
}
return idx;
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/BeneContact.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/BeneContact.java?rev=798868&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/BeneContact.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/BeneContact.java Wed Jul 29 12:09:16 2009
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.enhance.identity;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.MappedById;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Version;
+
+
+@Entity
+@Table(name="BENE_CONTACT")
+public class BeneContact {
+
+ private static final long serialVersionUID = 4571838649566012594L;
+
+ private BeneContactId id;
+
+ private Beneficiary beneficiary;
+
+ private String email;
+
+ private String phone;
+
+ private Date lastUpdateDate;
+
+ private int version;
+
+ @Version
+ public int getVersion() {
+ return version;
+ }
+
+ public void setVersion(int version) {
+ this.version = version;
+ }
+
+ @Temporal(TemporalType.TIMESTAMP)
+ public Date getLastUpdateDate() {
+ return lastUpdateDate;
+ }
+
+ public void setLastUpdateDate(Date lastUpdateDate) {
+ this.lastUpdateDate = lastUpdateDate;
+ }
+
+ @Column(name="EMAIL")
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ @Column(name="PHONE")
+ public String getPhone() {
+ return phone;
+ }
+
+ public void setPhone(String phone) {
+ this.phone = phone;
+ }
+
+ @EmbeddedId
+ public BeneContactId getId() {
+ return id;
+ }
+
+ public void setId(BeneContactId id) {
+ this.id = id;
+ }
+
+ @ManyToOne(targetEntity=Beneficiary.class, fetch=FetchType.EAGER)
+ @JoinColumn(name="ID")
+ @MappedById("beneficiaryPK")
+ public Beneficiary getBeneficiary() {
+ return beneficiary;
+ }
+
+ public void setBeneficiary(Beneficiary beneficiary) {
+ this.beneficiary = beneficiary;
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/BeneContact.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/BeneContactId.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/BeneContactId.java?rev=798868&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/BeneContactId.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/BeneContactId.java Wed Jul 29 12:09:16 2009
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.enhance.identity;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+
+@Embeddable
+public class BeneContactId implements Serializable {
+ private static final long serialVersionUID = -837443719842439462L;
+ ContactType type;
+
+ String beneficiaryPK;
+
+ public boolean equals(Object obj) {
+ if(this == obj) return true;
+ if((obj != null) && (obj instanceof BeneContactId)) {
+ BeneContactId other = (BeneContactId) obj;
+ if(this.type.equals(other.type) && this.beneficiaryPK.equals(other.beneficiaryPK))
+ return true;
+ }
+ return false;
+ }
+
+ public int hashCode() {
+ String hash = beneficiaryPK + Integer.toString(type.ordinal());
+ return hash.hashCode();
+ }
+
+ public String toString() {
+ return type.toString() + "-" + beneficiaryPK;
+ }
+
+ @Column(name="ID")
+ public String getBeneficiaryKey() {
+ return beneficiaryPK;
+ }
+
+ public void setBeneficiaryKey(String id) {
+ beneficiaryPK = id;
+ }
+
+ @Enumerated(EnumType.STRING)
+ @Column(name="TYPE")
+ public ContactType getContactType() {
+ return type;
+ }
+
+ public void setContactType(ContactType type) {
+ this.type = type;
+ }
+
+ public enum ContactType {HOME, BUSINESS, OTHER;}
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/BeneContactId.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Beneficiary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Beneficiary.java?rev=798868&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Beneficiary.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Beneficiary.java Wed Jul 29 12:09:16 2009
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.enhance.identity;
+
+import java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+
+@Entity
+@Table(name="BENEFICIARY")
+public class Beneficiary {
+
+ private static final long serialVersionUID = -452903666159175508L;
+
+ private String annuityHolderId;
+
+ private String firstName;
+
+ private String lastName;
+
+ private String relationship;
+
+ private List<BeneContact> contacts;
+
+ private String id;
+
+ @javax.persistence.Id
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @Column(name="FK_ANNUITY_HOLDER_ID")
+ public String getAnnuityHolderId() {
+ return annuityHolderId;
+ }
+
+ public void setAnnuityHolderId(String annuityHolderId) {
+ this.annuityHolderId = annuityHolderId;
+ }
+
+ @Column(name="FIRST_NAME")
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String first) {
+ this.firstName = first;
+ }
+
+ @Column(name="LAST_NAME")
+ public String getLastName() {
+ return lastName;
+ }
+ public void setLastName(String last) {
+ this.lastName = last;
+ }
+
+ @Column(name="RELATIONSHIP")
+ public String getRelationship() {
+ return relationship;
+ }
+
+ public void setRelationship(String relationship) {
+ this.relationship = relationship;
+ }
+
+ @OneToMany(targetEntity=BeneContact.class, mappedBy="beneficiary", fetch=FetchType.EAGER)
+ public List<BeneContact> getContacts() {
+ return contacts;
+ }
+
+ public void setContacts(List<BeneContact> contacts) {
+ this.contacts = contacts;
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Beneficiary.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMappedById.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMappedById.java?rev=798868&r1=798867&r2=798868&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMappedById.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMappedById.java Wed Jul 29 12:09:16 2009
@@ -86,7 +86,8 @@
Person2.class, Person3.class, MedicalHistory3.class,
Person4.class, PersonId4.class, MedicalHistory4.class,
Dependent3.class, Employee3.class, DependentId3.class,
- Parent3.class, Dependent4.class, Employee4.class);
+ Parent3.class, Dependent4.class, Employee4.class,
+ BeneContact.class, BeneContactId.class, Beneficiary.class);
}
/**
@@ -737,4 +738,29 @@
}
return e;
}
+
+ public void testEnumInEmbeddedId() {
+ EntityManager em = emf.createEntityManager();
+ Beneficiary b = new Beneficiary();
+ b.setId("b8");
+ List<BeneContact> contacts = new ArrayList<BeneContact>();
+ BeneContact c = new BeneContact();
+ c.setEmail("email8");
+ BeneContactId id = new BeneContactId();
+ id.setContactType(BeneContactId.ContactType.HOME);
+ c.setBeneficiary(b);
+
+ c.setId(id);
+ em.persist(c);
+ contacts.add(c);
+ b.setContacts(contacts);
+ em.persist(b);
+ em.getTransaction().begin();
+ em.flush();
+ em.getTransaction().commit();
+ em.clear();
+ BeneContactId id1 = c.getId();
+ BeneContact c1 = em.find(BeneContact.class, id1);
+ assertEquals("email8", c1.getEmail());
+ }
}