diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metamodel/BaseEmbeddedEntity.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/metamodel/BaseEmbeddedEntity.java new file mode 100644 index 0000000000..0180a2cde1 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/metamodel/BaseEmbeddedEntity.java @@ -0,0 +1,62 @@ + +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.jpa.test.metamodel; + +import java.io.Serializable; +import javax.persistence.EmbeddedId; +import javax.persistence.MappedSuperclass; + +/** + * @author Christian Beikov + */ +@MappedSuperclass +public abstract class BaseEmbeddedEntity implements Serializable { + + private I id; + + public BaseEmbeddedEntity() { + } + + public BaseEmbeddedEntity(I id) { + this.id = id; + } + + @EmbeddedId + public I getId() { + return id; + } + + public void setId(I id) { + this.id = id; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 47 * hash + (this.id != null ? this.id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final BaseEmbeddedEntity other = (BaseEmbeddedEntity) obj; + if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) { + return false; + } + return true; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metamodel/GenericsTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/metamodel/GenericsTest.java new file mode 100644 index 0000000000..a47df0bef2 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/metamodel/GenericsTest.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.jpa.test.metamodel; + +import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.TestForIssue; +import org.junit.Test; + +import javax.persistence.EntityManager; +import javax.persistence.metamodel.EmbeddableType; +import javax.persistence.metamodel.EntityType; +import javax.persistence.metamodel.ManagedType; +import javax.persistence.metamodel.SingularAttribute; + +import static org.junit.Assert.*; + +/** + * @author Christian Beikov + */ +@TestForIssue( jiraKey = "HHH-11540" ) +public class GenericsTest extends BaseEntityManagerFunctionalTestCase { + @Override + public Class[] getAnnotatedClasses() { + return new Class[] { + Person.class, + PersonId.class + }; + } + + @Test + public void testEmbeddableTypeExists() { + EntityManager em = getOrCreateEntityManager(); + EmbeddableType idType = em.getMetamodel().embeddable( PersonId.class) ; + assertNotNull( idType ); + em.close(); + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metamodel/Person.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/metamodel/Person.java new file mode 100644 index 0000000000..6940fd34ff --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/metamodel/Person.java @@ -0,0 +1,44 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.jpa.test.metamodel; + +import javax.persistence.Entity; + +/** + * @author Christian Beikov + */ +@Entity +public class Person extends BaseEmbeddedEntity { + + private String firstName; + private String lastName; + + public Person() { + } + + public Person(PersonId id, String firstName, String lastName) { + super(id); + this.firstName = firstName; + this.lastName = lastName; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metamodel/PersonId.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/metamodel/PersonId.java new file mode 100644 index 0000000000..7a92d74767 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/metamodel/PersonId.java @@ -0,0 +1,73 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.jpa.test.metamodel; + +import java.io.Serializable; +import javax.persistence.Embeddable; + +/** + * @author Christian Beikov + */ +@Embeddable +public class PersonId implements Serializable { + + private String ssn; + private String name; + + public PersonId() { + } + + public PersonId(String ssn, String name) { + this.ssn = ssn; + this.name = name; + } + + public String getSsn() { + return ssn; + } + + public void setSsn(String ssn) { + this.ssn = ssn; + } + + public String getName() { + return name; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 67 * hash + (this.ssn != null ? this.ssn.hashCode() : 0); + hash = 67 * hash + (this.name != null ? this.name.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final PersonId other = (PersonId) obj; + if ((this.ssn == null) ? (other.ssn != null) : !this.ssn.equals(other.ssn)) { + return false; + } + if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { + return false; + } + return true; + } + + public void setName(String name) { + this.name = name; + } +}