HHH-16938 Add test for issue

This commit is contained in:
Marco Belladelli 2023-08-07 14:30:14 +02:00
parent 489466f774
commit 224c31b70e
2 changed files with 29 additions and 2 deletions

View File

@ -7,6 +7,7 @@
package org.hibernate.orm.test.associations.any; package org.hibernate.orm.test.associations.any;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.testing.orm.junit.Jira;
import org.junit.Test; import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
@ -22,7 +23,8 @@ public class AnyTest extends BaseCoreFunctionalTestCase {
return new Class<?>[] { return new Class<?>[] {
IntegerProperty.class, IntegerProperty.class,
StringProperty.class, StringProperty.class,
PropertyHolder.class PropertyHolder.class,
PropertyHolder2.class,
}; };
} }
@ -71,4 +73,29 @@ public class AnyTest extends BaseCoreFunctionalTestCase {
} }
@Test
@Jira( "https://hibernate.atlassian.net/browse/HHH-16938" )
public void testMetaAnnotated() {
doInHibernate( this::sessionFactory, session -> {
final StringProperty nameProperty = new StringProperty();
nameProperty.setId( 2L );
nameProperty.setName( "name2" );
nameProperty.setValue( "Mario Rossi" );
session.persist( nameProperty );
final PropertyHolder2 namePropertyHolder = new PropertyHolder2();
namePropertyHolder.setId( 2L );
namePropertyHolder.setProperty( nameProperty );
session.persist( namePropertyHolder );
} );
doInHibernate( this::sessionFactory, session -> {
final PropertyHolder2 propertyHolder = session.get( PropertyHolder2.class, 2L );
assertEquals( "name2", propertyHolder.getProperty().getName() );
assertEquals( "Mario Rossi", propertyHolder.getProperty().getValue() );
final String propertyType = session.createNativeQuery(
"select property_type from property_holder2",
String.class
).getSingleResult();
assertEquals( "S", propertyType );
} );
}
} }

View File

@ -16,7 +16,7 @@ import jakarta.persistence.Table;
//tag::associations-any-def-example[] //tag::associations-any-def-example[]
@Entity @Entity
@Table(name = "property_holder") @Table(name = "property_holder2")
public class PropertyHolder2 { public class PropertyHolder2 {
@Id @Id