HHH-6608 Replaced dot of path to property of many-to-one inside a component
This commit is contained in:
parent
edeecef3cf
commit
f5e6ada7d8
|
@ -268,7 +268,7 @@ public class BinderHelper {
|
||||||
*/
|
*/
|
||||||
StringBuilder propertyNameBuffer = new StringBuilder( "_" );
|
StringBuilder propertyNameBuffer = new StringBuilder( "_" );
|
||||||
propertyNameBuffer.append( associatedClass.getEntityName().replace( '.', '_' ) );
|
propertyNameBuffer.append( associatedClass.getEntityName().replace( '.', '_' ) );
|
||||||
propertyNameBuffer.append( "_" ).append( columns[0].getPropertyName() );
|
propertyNameBuffer.append( "_" ).append( columns[0].getPropertyName().replace( '.', '_' ) );
|
||||||
String syntheticPropertyName = propertyNameBuffer.toString();
|
String syntheticPropertyName = propertyNameBuffer.toString();
|
||||||
//find properties associated to a certain column
|
//find properties associated to a certain column
|
||||||
Object columnOwner = findColumnOwner( ownerEntity, columns[0].getReferencedColumn(), mappings );
|
Object columnOwner = findColumnOwner( ownerEntity, columns[0].getReferencedColumn(), mappings );
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package org.hibernate.test.annotations.referencedcolumnname;
|
||||||
|
|
||||||
|
import javax.persistence.AssociationOverride;
|
||||||
|
import javax.persistence.AssociationOverrides;
|
||||||
|
import javax.persistence.Embedded;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Janario Oliveira
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class HousePlaces {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
int id;
|
||||||
|
@Embedded
|
||||||
|
Places places;
|
||||||
|
@Embedded
|
||||||
|
@AssociationOverrides({
|
||||||
|
@AssociationOverride(name = "livingRoom", joinColumns = {
|
||||||
|
@JoinColumn(name = "NEIGHBOUR_LIVINGROOM", referencedColumnName = "NAME"),
|
||||||
|
@JoinColumn(name = "NEIGHBOUR_LIVINGROOM_OWNER", referencedColumnName = "OWNER") }),
|
||||||
|
@AssociationOverride(name = "kitchen", joinColumns = @JoinColumn(name = "NEIGHBOUR_KITCHEN", referencedColumnName = "NAME")) })
|
||||||
|
Places neighbourPlaces;
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package org.hibernate.test.annotations.referencedcolumnname;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Janario Oliveira
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class Place {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
int id;
|
||||||
|
@Column(name = "NAME")
|
||||||
|
String name;
|
||||||
|
@Column(name = "OWNER")
|
||||||
|
String owner;
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package org.hibernate.test.annotations.referencedcolumnname;
|
||||||
|
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
|
import javax.persistence.Embeddable;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.JoinColumns;
|
||||||
|
import javax.persistence.ManyToOne;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Janario Oliveira
|
||||||
|
*/
|
||||||
|
@Embeddable
|
||||||
|
public class Places {
|
||||||
|
|
||||||
|
@ManyToOne(cascade = CascadeType.ALL)
|
||||||
|
@JoinColumns({ @JoinColumn(name = "LIVING_ROOM", referencedColumnName = "NAME"),
|
||||||
|
@JoinColumn(name = "LIVING_ROOM_OWNER", referencedColumnName = "OWNER") })
|
||||||
|
Place livingRoom;
|
||||||
|
@ManyToOne(cascade = CascadeType.ALL)
|
||||||
|
@JoinColumn(name = "KITCHEN", referencedColumnName = "NAME")
|
||||||
|
Place kitchen;
|
||||||
|
}
|
|
@ -23,17 +23,17 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.annotations.referencedcolumnname;
|
package org.hibernate.test.annotations.referencedcolumnname;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.criterion.Restrictions;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
|
@ -206,6 +206,68 @@ public class ReferencedColumnNameTest extends BaseCoreFunctionalTestCase {
|
||||||
s.close();
|
s.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testManyToOneInsideComponentReferencedColumn() {
|
||||||
|
HousePlaces house = new HousePlaces();
|
||||||
|
house.places = new Places();
|
||||||
|
|
||||||
|
house.places.livingRoom = new Place();
|
||||||
|
house.places.livingRoom.name = "First";
|
||||||
|
house.places.livingRoom.owner = "mine";
|
||||||
|
|
||||||
|
house.places.kitchen = new Place();
|
||||||
|
house.places.kitchen.name = "Kitchen 1";
|
||||||
|
|
||||||
|
house.neighbourPlaces = new Places();
|
||||||
|
house.neighbourPlaces.livingRoom = new Place();
|
||||||
|
house.neighbourPlaces.livingRoom.name = "Neighbour";
|
||||||
|
house.neighbourPlaces.livingRoom.owner = "his";
|
||||||
|
|
||||||
|
house.neighbourPlaces.kitchen = new Place();
|
||||||
|
house.neighbourPlaces.kitchen.name = "His Kitchen";
|
||||||
|
|
||||||
|
Session s = openSession();
|
||||||
|
Transaction tx = s.beginTransaction();
|
||||||
|
s.save( house );
|
||||||
|
s.flush();
|
||||||
|
|
||||||
|
HousePlaces get = (HousePlaces) s.get( HousePlaces.class, house.id );
|
||||||
|
assertEquals( house.id, get.id );
|
||||||
|
|
||||||
|
HousePlaces uniqueResult = (HousePlaces) s.createQuery(
|
||||||
|
"from HousePlaces h where h.places.livingRoom.name='First'" ).uniqueResult();
|
||||||
|
assertNotNull( uniqueResult );
|
||||||
|
assertEquals( uniqueResult.places.livingRoom.name, "First" );
|
||||||
|
assertEquals( uniqueResult.places.livingRoom.owner, "mine" );
|
||||||
|
|
||||||
|
uniqueResult = (HousePlaces) s.createQuery( "from HousePlaces h where h.places.livingRoom.owner=:owner" )
|
||||||
|
.setParameter( "owner", "mine" ).uniqueResult();
|
||||||
|
assertNotNull( uniqueResult );
|
||||||
|
assertEquals( uniqueResult.places.livingRoom.name, "First" );
|
||||||
|
assertEquals( uniqueResult.places.livingRoom.owner, "mine" );
|
||||||
|
|
||||||
|
assertNotNull( s.createCriteria( HousePlaces.class ).add( Restrictions.eq( "places.livingRoom.owner", "mine" ) )
|
||||||
|
.uniqueResult() );
|
||||||
|
|
||||||
|
// override
|
||||||
|
uniqueResult = (HousePlaces) s
|
||||||
|
.createQuery( "from HousePlaces h where h.neighbourPlaces.livingRoom.owner='his'" ).uniqueResult();
|
||||||
|
assertNotNull( uniqueResult );
|
||||||
|
assertEquals( uniqueResult.neighbourPlaces.livingRoom.name, "Neighbour" );
|
||||||
|
assertEquals( uniqueResult.neighbourPlaces.livingRoom.owner, "his" );
|
||||||
|
|
||||||
|
uniqueResult = (HousePlaces) s.createQuery( "from HousePlaces h where h.neighbourPlaces.livingRoom.name=:name" )
|
||||||
|
.setParameter( "name", "Neighbour" ).uniqueResult();
|
||||||
|
assertNotNull( uniqueResult );
|
||||||
|
assertEquals( uniqueResult.neighbourPlaces.livingRoom.name, "Neighbour" );
|
||||||
|
assertEquals( uniqueResult.neighbourPlaces.livingRoom.owner, "his" );
|
||||||
|
|
||||||
|
assertNotNull( s.createCriteria( HousePlaces.class )
|
||||||
|
.add( Restrictions.eq( "neighbourPlaces.livingRoom.owner", "his" ) ).uniqueResult() );
|
||||||
|
|
||||||
|
tx.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class[] getAnnotatedClasses() {
|
protected Class[] getAnnotatedClasses() {
|
||||||
return new Class[]{
|
return new Class[]{
|
||||||
|
@ -219,7 +281,9 @@ public class ReferencedColumnNameTest extends BaseCoreFunctionalTestCase {
|
||||||
Item.class,
|
Item.class,
|
||||||
ItemCost.class,
|
ItemCost.class,
|
||||||
Vendor.class,
|
Vendor.class,
|
||||||
WarehouseItem.class
|
WarehouseItem.class,
|
||||||
|
Place.class,
|
||||||
|
HousePlaces.class
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue