HHH-14241 Support ImplicitNamingStrategyComponentPathImpl with IdClass
Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
parent
03416a8cdd
commit
8d4de09255
|
@ -8,6 +8,7 @@ package org.hibernate.boot.model.naming;
|
|||
|
||||
import org.hibernate.boot.model.source.spi.AttributePath;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.loader.PropertyPath;
|
||||
|
||||
/**
|
||||
* An ImplicitNamingStrategy implementation which uses full composite paths
|
||||
|
@ -30,14 +31,17 @@ public class ImplicitNamingStrategyComponentPathImpl extends ImplicitNamingStrat
|
|||
}
|
||||
|
||||
public static void process(AttributePath attributePath, StringBuilder sb) {
|
||||
if ( attributePath.getParent() != null ) {
|
||||
process( attributePath.getParent(), sb );
|
||||
if ( StringHelper.isNotEmpty( attributePath.getParent().getProperty() ) ) {
|
||||
sb.append( '_' );
|
||||
}
|
||||
}
|
||||
|
||||
String property = attributePath.getProperty();
|
||||
final AttributePath parent = attributePath.getParent();
|
||||
if ( parent != null && StringHelper.isNotEmpty( parent.getProperty() ) ) {
|
||||
process( parent, sb );
|
||||
sb.append( '_' );
|
||||
}
|
||||
else if ( PropertyPath.IDENTIFIER_MAPPER_PROPERTY.equals( property ) ) {
|
||||
// skip it, do not pass go
|
||||
sb.append( "id" );
|
||||
return;
|
||||
}
|
||||
property = property.replace( "<", "" );
|
||||
property = property.replace( ">", "" );
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ package org.hibernate.id.idclass;
|
|||
import org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -21,10 +22,10 @@ public class IdClassNamingStrategyTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
/*
|
||||
* With this implicit naming strategy, we got the following mapping:
|
||||
*
|
||||
* create table MyEntity (
|
||||
/*
|
||||
* With this implicit naming strategy, we got the following mapping:
|
||||
*
|
||||
* create table MyEntity (
|
||||
* id_idA bigint not null,
|
||||
* id_idB bigint not null,
|
||||
* _identifierMapper_idA bigint not null, <-- ??
|
||||
|
@ -32,11 +33,12 @@ public class IdClassNamingStrategyTest extends BaseCoreFunctionalTestCase {
|
|||
* notes varchar(255),
|
||||
* primary key (id_idA, id_idB)
|
||||
* )
|
||||
*/
|
||||
*/
|
||||
configuration.setImplicitNamingStrategy( new ImplicitNamingStrategyComponentPathImpl() );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-14241")
|
||||
public void test() {
|
||||
inTransaction( ( session ) -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
|
|
|
@ -23,12 +23,12 @@ public class MyEntity {
|
|||
private String notes;
|
||||
|
||||
public MyEntityId getId() {
|
||||
return new MyEntityId( idB, idA );
|
||||
return new MyEntityId( idA, idB );
|
||||
}
|
||||
|
||||
public void setId(MyEntityId id) {
|
||||
this.idB = id.getIdA();
|
||||
this.idA = id.getIdB();
|
||||
this.idA = id.getIdA();
|
||||
this.idB = id.getIdB();
|
||||
}
|
||||
|
||||
public String getNotes() {
|
||||
|
|
Loading…
Reference in New Issue