HHH-18103 Add test for issue
This commit is contained in:
parent
ac4931a264
commit
00c7707de0
|
@ -7,27 +7,31 @@
|
|||
package org.hibernate.orm.test.metamodel;
|
||||
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
|
||||
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Jira;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static jakarta.persistence.metamodel.Type.PersistenceType.MAPPED_SUPERCLASS;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
||||
@Jpa(
|
||||
annotatedClasses = {
|
||||
@Jpa( annotatedClasses = {
|
||||
ProductEntity.class,
|
||||
LocalizedValue.class,
|
||||
Company.class,
|
||||
Address.class,
|
||||
Person.class,
|
||||
Company.class
|
||||
}
|
||||
)
|
||||
Measurement.class,
|
||||
Height.class,
|
||||
} )
|
||||
public class EmbeddableMetaModelTest {
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-11111")
|
||||
@Jira( "https://hibernate.atlassian.net/browse/HHH-11111" )
|
||||
public void testEmbeddableCanBeResolvedWhenUsedAsInterface(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
assertNotNull( entityManager.getMetamodel().embeddable( LocalizedValue.class ) );
|
||||
|
@ -36,13 +40,26 @@ public class EmbeddableMetaModelTest {
|
|||
} );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-12124")
|
||||
@Jira( "https://hibernate.atlassian.net/browse/HHH-12124" )
|
||||
public void testEmbeddableEquality(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
assertTrue( entityManager.getMetamodel().getEmbeddables().contains( Company_.address.getType() ) );
|
||||
assertTrue( entityManager.getMetamodel().getEmbeddables().contains( Person_.address.getType() ) );
|
||||
assertTrue( entityManager.getMetamodel().getEmbeddables().contains( Person_.height.getType() ) );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
@Jira( "https://hibernate.atlassian.net/browse/HHH-18103" )
|
||||
public void test(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
final EmbeddableDomainType<Height> embeddable = (EmbeddableDomainType<Height>) entityManager.getMetamodel()
|
||||
.embeddable( Height.class );
|
||||
assertNotNull( embeddable.getSuperType() );
|
||||
assertEquals( MAPPED_SUPERCLASS, embeddable.getSuperType().getPersistenceType() );
|
||||
assertEquals( Measurement.class, embeddable.getSuperType().getJavaType() );
|
||||
assertNotNull( Height_.height );
|
||||
assertNotNull( Measurement_.unit );
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* 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.orm.test.metamodel;
|
||||
|
||||
import jakarta.persistence.Embeddable;
|
||||
|
||||
/**
|
||||
* @author Marco Belladelli
|
||||
*/
|
||||
@Embeddable
|
||||
public class Height extends Measurement {
|
||||
private float height;
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* 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.orm.test.metamodel;
|
||||
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
|
||||
/**
|
||||
* @author Marco Belladelli
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public abstract class Measurement {
|
||||
private String unit;
|
||||
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
public void setUnit(String unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@ public class Person implements Serializable {
|
|||
private String name;
|
||||
|
||||
@Embedded
|
||||
private Address address = new Address();
|
||||
private Height height;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
|
@ -41,11 +41,11 @@ public class Person implements Serializable {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public Address getAddress() {
|
||||
return address;
|
||||
public Height getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setAddress(Address address) {
|
||||
this.address = address;
|
||||
public void setHeight(Height height) {
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue