HHH-15696 very basic test for multiply-mapped entity class

This commit is contained in:
Gavin King 2022-11-09 15:19:41 +01:00
parent 1cc7b72c4c
commit 89c1b0f0ce
4 changed files with 129 additions and 1 deletions

View File

@ -0,0 +1,45 @@
/*
* 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.entityname;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@DomainModel(xmlMappings = { "org/hibernate/orm/test/entityname/MyEntity.hbm.xml" })
@SessionFactory
public class MultipleMappingsTest {
@Test
public void test(SessionFactoryScope scope) {
MyEntity entity1 = new MyEntity();
entity1.setName("One");
MyEntity entity2 = new MyEntity();
entity2.setName("Two");
entity1.setOther(entity2);
entity2.setOther(entity1);
scope.inTransaction(s -> {
s.persist("EntityWon", entity1 );
s.persist("EntityToo", entity2 );
});
scope.inTransaction(s -> {
MyEntity entity = (MyEntity) s.get("EntityWon", entity1.getId());
assertNotNull( entity );
assertEquals( "One", entity.getName() );
MyEntity other = entity.getOther();
assertEquals( "Two", other.getName() );
assertEquals( other.getId(), entity2.getId() );
entity.setOther( null );
s.remove( other );
s.remove( entity );
});
}
}

View File

@ -0,0 +1,31 @@
<?xml version="1.0"?>
<!--
~ 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>.
-->
<!DOCTYPE hibernate-mapping SYSTEM "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="org.hibernate.orm.test.entityname">
<class name="MyEntity" entity-name="EntityWon" table="EntityWon">
<id name="id" column="ID" type="long">
<generator class="increment"/>
</id>
<property name="name" type="string"/>
<property name="surname" type="string"/>
<many-to-one name="other" entity-name="EntityToo"/>
</class>
<class name="MyEntity" entity-name="EntityToo" table="EntityToo">
<id name="id" column="ID" type="long">
<generator class="increment"/>
</id>
<property name="name" type="string"/>
<property name="surname" type="string"/>
<many-to-one name="other" entity-name="EntityWon"/>
</class>
</hibernate-mapping>

View File

@ -0,0 +1,52 @@
/*
* 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.entityname;
/**
* {@inheritDoc}
*
* @author Steve Ebersole
*/
public class MyEntity {
private Long id;
private String name;
private String surname;
private MyEntity other;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public MyEntity getOther() {
return other;
}
public void setOther(MyEntity other) {
this.other = other;
}
}

View File

@ -51,7 +51,7 @@ public @interface SessionFactory {
Class<? extends StatementInspector> statementInspectorClass() default StatementInspector.class;
/**
* Short hand for {@code statementInspectorClass = org.hibernate.testing.jdbc.SQLStatementInspector.class}
* Shorthand for {@code statementInspectorClass = org.hibernate.testing.jdbc.SQLStatementInspector.class}
*
* @see SQLStatementInspector
*/