HHH-11540 - Test for embeddable type that is only used in a type variable

This commit is contained in:
Christian Beikov 2017-01-03 17:34:26 +01:00 committed by Andrea Boriero
parent 6fd6c5a29d
commit ff582903aa
4 changed files with 221 additions and 0 deletions

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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<I extends Serializable> 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;
}
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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<PersonId> idType = em.getMetamodel().embeddable( PersonId.class) ;
assertNotNull( idType );
em.close();
}
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.test.metamodel;
import javax.persistence.Entity;
/**
* @author Christian Beikov
*/
@Entity
public class Person extends BaseEmbeddedEntity<PersonId> {
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;
}
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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;
}
}