HHH-18060 - HbXmlTransformer work
non-aggregated composite id
This commit is contained in:
parent
330ad18288
commit
4d0422fe05
|
@ -1146,7 +1146,7 @@ public class XmlAnnotationHelper {
|
|||
JaxbIdClassImpl jaxbIdClass,
|
||||
MutableClassDetails target,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( jaxbIdClass == null ) {
|
||||
if ( jaxbIdClass == null || StringHelper.isEmpty( jaxbIdClass.getClazz() ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* 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.boot.models.hbm.ecid;
|
||||
|
||||
import org.hibernate.cfg.MappingSettings;
|
||||
import org.hibernate.orm.test.abstractembeddedcomponents.cid.AbstractCompositeIdTest;
|
||||
import org.hibernate.orm.test.abstractembeddedcomponents.cid.MyInterfaceImpl;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.FailureExpected;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @see AbstractCompositeIdTest
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@SuppressWarnings("JUnitMalformedDeclaration")
|
||||
@ServiceRegistry(settings = @Setting(name= MappingSettings.TRANSFORM_HBM_XML, value="true"))
|
||||
@DomainModel( xmlMappings = "org/hibernate/orm/test/abstractembeddedcomponents/cid/Mappings.hbm.xml" )
|
||||
@SessionFactory
|
||||
@FailureExpected
|
||||
public class EmbeddedCompositeIdentifierOnAbstractClassTests {
|
||||
|
||||
@Test
|
||||
public void testTransformedHbmXml(SessionFactoryScope scope) {
|
||||
MyInterfaceImpl myInterface = new MyInterfaceImpl();
|
||||
myInterface.setKey1( "key1" );
|
||||
myInterface.setKey2( "key2" );
|
||||
myInterface.setName( "test" );
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
// test persistence
|
||||
session.persist( myInterface );
|
||||
session.flush();
|
||||
|
||||
// test loading
|
||||
session.createQuery( "from MyInterface" ).list();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void dropTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction( (session) -> {
|
||||
session.createMutationQuery( "delete MyInterface" ).executeUpdate();
|
||||
} );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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.boot.models.hbm.ecid;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Login {
|
||||
private String system;
|
||||
private String username;
|
||||
private String email;
|
||||
|
||||
public Login() {
|
||||
}
|
||||
|
||||
public Login(String system, String username, String email) {
|
||||
this.system = system;
|
||||
this.username = username;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getSystem() {
|
||||
return system;
|
||||
}
|
||||
|
||||
public void setSystem(String system) {
|
||||
this.system = system;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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.boot.models.hbm.ecid;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.cfg.MappingSettings;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@SuppressWarnings("JUnitMalformedDeclaration")
|
||||
@ServiceRegistry(settings = @Setting(name= MappingSettings.TRANSFORM_HBM_XML, value="true"))
|
||||
@DomainModel(xmlMappings = "mappings/models/hbm/ecid/standard-ecid.hbm.xml")
|
||||
@SessionFactory
|
||||
public class StandardNonAggregatedIdTests {
|
||||
@Test
|
||||
void simpleTest(SessionFactoryScope scope) {
|
||||
final Login login = new Login( "prod", "john", "john@doe.com" );
|
||||
scope.inTransaction( (session) -> session.persist( login ) );
|
||||
|
||||
scope.inTransaction( (session) -> {
|
||||
final List<Login> logins = session.createSelectionQuery( "from Login", Login.class ).list();
|
||||
assertThat( logins ).hasSize( 1 );
|
||||
} );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?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 PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping>
|
||||
|
||||
<class name="org.hibernate.orm.test.boot.models.hbm.ecid.Login" table="user_logins">
|
||||
<composite-id>
|
||||
<key-property name="system"/>
|
||||
<key-property name="username"/>
|
||||
</composite-id>
|
||||
<property name="email"/>
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
Loading…
Reference in New Issue