HHH-6381 - handle optional=true joins for SecondaryTables in the JoinedSubclassEntityPersister
This commit is contained in:
parent
7c84b08391
commit
20559966b3
|
@ -110,6 +110,11 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
|||
|
||||
private final String discriminatorSQLString;
|
||||
|
||||
//Span of the tables directly mapped by this entity and super-classes, if any
|
||||
private final int coreTableSpan;
|
||||
// only contains values for SecondaryTables ie. not tables part of the "coreTableSpan"
|
||||
private final boolean[] isNullableTable;
|
||||
|
||||
//INITIALIZATION:
|
||||
|
||||
public JoinedSubclassEntityPersister(
|
||||
|
@ -178,12 +183,17 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
|||
}
|
||||
|
||||
//Span of the tables directly mapped by this entity and super-classes, if any
|
||||
int coreTableSpan = tables.size();
|
||||
|
||||
coreTableSpan = tables.size();
|
||||
|
||||
isNullableTable = new boolean[persistentClass.getJoinClosureSpan()];
|
||||
|
||||
int tabIndex = 0;
|
||||
Iterator joinIter = persistentClass.getJoinClosureIterator();
|
||||
while ( joinIter.hasNext() ) {
|
||||
Join join = (Join) joinIter.next();
|
||||
|
||||
isNullableTable[tabIndex++] = join.isOptional();
|
||||
|
||||
Table tab = join.getTable();
|
||||
|
||||
String tabname = tab.getQualifiedName(
|
||||
|
@ -528,6 +538,14 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
|||
constraintOrderedTableNames = null;
|
||||
constraintOrderedKeyColumnNames = null;
|
||||
discriminatorSQLString = null;
|
||||
coreTableSpan = -1;
|
||||
isNullableTable = null;
|
||||
}
|
||||
|
||||
protected boolean isNullableTable(int j) {
|
||||
if (j < coreTableSpan)
|
||||
return false;
|
||||
return isNullableTable[j-coreTableSpan];
|
||||
}
|
||||
|
||||
protected boolean isSubclassTableSequentialSelect(int j) {
|
||||
|
|
|
@ -30,6 +30,9 @@ import org.junit.Test;
|
|||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
|
@ -39,8 +42,25 @@ public class JoinedSubclassAndSecondaryTable extends BaseCoreFunctionalTestCase
|
|||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
SwimmingPool sp = new SwimmingPool();
|
||||
sp.setAddress( "Park Avenue" );
|
||||
//sp.setAddress( "Park Avenue" );
|
||||
s.persist( sp );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
SwimmingPool sp2 = (SwimmingPool)s.get(SwimmingPool.class, sp.getId());
|
||||
assertEquals( sp.getAddress(), null);
|
||||
|
||||
PoolAddress addr = new PoolAddress();
|
||||
addr.setAddress("Park Avenue");
|
||||
sp2.setAddress(addr);
|
||||
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
sp2 = (SwimmingPool)s.get(SwimmingPool.class, sp.getId());
|
||||
assertFalse( sp2.getAddress() == null );
|
||||
assertEquals( sp2.getAddress().getAddress(), "Park Avenue");
|
||||
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//$Id$
|
||||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
@ -14,16 +15,19 @@ import javax.persistence.SecondaryTable;
|
|||
@Entity
|
||||
@Inheritance(strategy = InheritanceType.JOINED)
|
||||
@SecondaryTable(name="POOL_ADDRESS")
|
||||
@org.hibernate.annotations.Table(appliesTo="POOL_ADDRESS", optional=true)
|
||||
public class Pool {
|
||||
@Id @GeneratedValue private Integer id;
|
||||
@Column(table = "POOL_ADDRESS")
|
||||
private String address;
|
||||
@Id @GeneratedValue
|
||||
private Integer id;
|
||||
|
||||
@Embedded
|
||||
private PoolAddress address;
|
||||
|
||||
public String getAddress() {
|
||||
public PoolAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
public void setAddress(PoolAddress address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package org.hibernate.test.annotations.inheritance.joined;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
@Embeddable
|
||||
public class PoolAddress {
|
||||
@Column(table = "POOL_ADDRESS")
|
||||
private String address;
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue