HHH-6813 @Id @OneToOne cause NullPointerException during query
This commit is contained in:
parent
8b9ec5cca5
commit
bc6f5d8a17
|
@ -341,6 +341,7 @@ public class BinderHelper {
|
|||
*/
|
||||
if ( value instanceof ToOne ) {
|
||||
( (ToOne) value ).setReferencedPropertyName( syntheticPropertyName );
|
||||
( (ToOne) value ).setReferenceToPrimaryKey( syntheticPropertyName == null );
|
||||
mappings.addUniquePropertyReference( ownerEntity.getEntityName(), syntheticPropertyName );
|
||||
}
|
||||
else if ( value instanceof Collection ) {
|
||||
|
|
|
@ -1629,6 +1629,7 @@ public final class HbmBinder {
|
|||
if ( ukName != null ) {
|
||||
manyToOne.setReferencedPropertyName( ukName.getValue() );
|
||||
}
|
||||
manyToOne.setReferenceToPrimaryKey( manyToOne.getReferencedPropertyName() == null );
|
||||
|
||||
manyToOne.setReferencedEntityName( getEntityName( node, mappings ) );
|
||||
|
||||
|
@ -1728,6 +1729,7 @@ public final class HbmBinder {
|
|||
|
||||
Attribute ukName = node.attribute( "property-ref" );
|
||||
if ( ukName != null ) oneToOne.setReferencedPropertyName( ukName.getValue() );
|
||||
oneToOne.setReferenceToPrimaryKey( oneToOne.getReferencedPropertyName() == null );
|
||||
|
||||
oneToOne.setPropertyName( node.attributeValue( "name" ) );
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.hibernate.mapping.ManyToOne;
|
|||
import org.hibernate.mapping.OneToOne;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.mapping.Selectable;
|
||||
import org.hibernate.mapping.SimpleValue;
|
||||
import org.hibernate.type.ForeignKeyDirection;
|
||||
|
||||
|
@ -212,12 +213,10 @@ public class OneToOneSecondPass implements SecondPass {
|
|||
else {
|
||||
propertyHolder.addProperty( prop, inferredData.getDeclaringClass() );
|
||||
}
|
||||
|
||||
value.setReferencedPropertyName( mappedBy );
|
||||
|
||||
// HHH-6813
|
||||
// If otherSide's id is derived, do not set EntityType#uniqueKeyPropertyName.
|
||||
// EntityType#isReferenceToPrimaryKey() assumes that, if it's set,
|
||||
// a PK is not referenced. Example:
|
||||
//
|
||||
// Foo: @Id long id, @OneToOne(mappedBy="foo") Bar bar
|
||||
// Bar: @Id @OneToOne Foo foo
|
||||
boolean referencesDerivedId = false;
|
||||
|
@ -228,8 +227,14 @@ public class OneToOneSecondPass implements SecondPass {
|
|||
catch ( MappingException e ) {
|
||||
// ignore
|
||||
}
|
||||
String referencedPropertyName = referencesDerivedId ? null : mappedBy;
|
||||
value.setReferencedPropertyName( referencedPropertyName );
|
||||
boolean referenceToPrimaryKey = referencesDerivedId || mappedBy == null;
|
||||
value.setReferenceToPrimaryKey( referenceToPrimaryKey );
|
||||
|
||||
// If the other side is a derived ID, prevent an infinite
|
||||
// loop of attempts to resolve identifiers.
|
||||
if ( referencesDerivedId ) {
|
||||
( (ManyToOne) otherSideProperty.getValue() ).setReferenceToPrimaryKey( false );
|
||||
}
|
||||
|
||||
String propertyRef = value.getReferencedPropertyName();
|
||||
if ( propertyRef != null ) {
|
||||
|
|
|
@ -1484,6 +1484,7 @@ public abstract class CollectionBinder {
|
|||
( (ManyToOne) value ).setReferencedPropertyName( referencedPropertyName );
|
||||
mappings.addUniquePropertyReference( referencedEntity.getEntityName(), referencedPropertyName );
|
||||
}
|
||||
( (ManyToOne) value ).setReferenceToPrimaryKey( referencedPropertyName == null );
|
||||
value.createForeignKey();
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -45,7 +45,8 @@ public class ManyToOne extends ToOne {
|
|||
|
||||
public Type getType() throws MappingException {
|
||||
return getMappings().getTypeResolver().getTypeFactory().manyToOne(
|
||||
getReferencedEntityName(),
|
||||
getReferencedEntityName(),
|
||||
referenceToPrimaryKey,
|
||||
getReferencedPropertyName(),
|
||||
isLazy(),
|
||||
isUnwrapProxy(),
|
||||
|
|
|
@ -47,7 +47,8 @@ public class OneToMany implements Value {
|
|||
|
||||
private EntityType getEntityType() {
|
||||
return mappings.getTypeResolver().getTypeFactory().manyToOne(
|
||||
getReferencedEntityName(),
|
||||
getReferencedEntityName(),
|
||||
true,
|
||||
null,
|
||||
false,
|
||||
false,
|
||||
|
|
|
@ -69,7 +69,8 @@ public class OneToOne extends ToOne {
|
|||
if ( getColumnIterator().hasNext() ) {
|
||||
return getMappings().getTypeResolver().getTypeFactory().specialOneToOne(
|
||||
getReferencedEntityName(),
|
||||
foreignKeyType,
|
||||
foreignKeyType,
|
||||
referenceToPrimaryKey,
|
||||
referencedPropertyName,
|
||||
isLazy(),
|
||||
isUnwrapProxy(),
|
||||
|
@ -80,7 +81,8 @@ public class OneToOne extends ToOne {
|
|||
else {
|
||||
return getMappings().getTypeResolver().getTypeFactory().oneToOne(
|
||||
getReferencedEntityName(),
|
||||
foreignKeyType,
|
||||
foreignKeyType,
|
||||
referenceToPrimaryKey,
|
||||
referencedPropertyName,
|
||||
isLazy(),
|
||||
isUnwrapProxy(),
|
||||
|
|
|
@ -41,6 +41,7 @@ public abstract class ToOne extends SimpleValue implements Fetchable {
|
|||
private boolean embedded;
|
||||
private boolean lazy = true;
|
||||
protected boolean unwrapProxy;
|
||||
protected boolean referenceToPrimaryKey = true;
|
||||
|
||||
protected ToOne(Mappings mappings, Table table) {
|
||||
super( mappings, table );
|
||||
|
@ -129,5 +130,13 @@ public abstract class ToOne extends SimpleValue implements Fetchable {
|
|||
public void setUnwrapProxy(boolean unwrapProxy) {
|
||||
this.unwrapProxy = unwrapProxy;
|
||||
}
|
||||
|
||||
public boolean isReferenceToPrimaryKey() {
|
||||
return referenceToPrimaryKey;
|
||||
}
|
||||
|
||||
public void setReferenceToPrimaryKey(boolean referenceToPrimaryKey) {
|
||||
this.referenceToPrimaryKey = referenceToPrimaryKey;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,11 @@
|
|||
*/
|
||||
package org.hibernate.type;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.Node;
|
||||
import org.hibernate.AssertionFailure;
|
||||
|
@ -30,7 +35,11 @@ import org.hibernate.EntityMode;
|
|||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.engine.internal.ForeignKeys;
|
||||
import org.hibernate.engine.spi.*;
|
||||
import org.hibernate.engine.spi.EntityUniqueKey;
|
||||
import org.hibernate.engine.spi.Mapping;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.persister.entity.Joinable;
|
||||
|
@ -38,11 +47,6 @@ import org.hibernate.persister.entity.UniqueKeyLoadable;
|
|||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.tuple.ElementWrapper;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Base for types which map associations to persistent entities.
|
||||
*
|
||||
|
@ -56,6 +60,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
|
|||
protected final boolean isEmbeddedInXML;
|
||||
private final boolean eager;
|
||||
private final boolean unwrapProxy;
|
||||
private final boolean referenceToPrimaryKey;
|
||||
|
||||
private transient Class returnedClass;
|
||||
|
||||
|
@ -72,7 +77,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
|
|||
* says to return the "implementation target" of lazy prooxies; typically only possible
|
||||
* with lazy="no-proxy".
|
||||
*
|
||||
* @deprecated Use {@link #EntityType(TypeFactory.TypeScope, String, String, boolean, boolean )} instead.
|
||||
* @deprecated Use {@link #EntityType(org.hibernate.type.TypeFactory.TypeScope, String, boolean, String, boolean, boolean)} instead.
|
||||
* See Jira issue: <a href="https://hibernate.onjira.com/browse/HHH-7771">HHH-7771</a>
|
||||
*/
|
||||
@Deprecated
|
||||
|
@ -83,12 +88,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
|
|||
boolean eager,
|
||||
boolean isEmbeddedInXML,
|
||||
boolean unwrapProxy) {
|
||||
this.scope = scope;
|
||||
this.associatedEntityName = entityName;
|
||||
this.uniqueKeyPropertyName = uniqueKeyPropertyName;
|
||||
this.isEmbeddedInXML = isEmbeddedInXML;
|
||||
this.eager = eager;
|
||||
this.unwrapProxy = unwrapProxy;
|
||||
this( scope, entityName, uniqueKeyPropertyName == null, uniqueKeyPropertyName, eager, unwrapProxy );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,10 +102,36 @@ public abstract class EntityType extends AbstractType implements AssociationType
|
|||
* @param unwrapProxy Is unwrapping of proxies allowed for this association; unwrapping
|
||||
* says to return the "implementation target" of lazy prooxies; typically only possible
|
||||
* with lazy="no-proxy".
|
||||
*
|
||||
* @deprecated Use {@link #EntityType(org.hibernate.type.TypeFactory.TypeScope, String, boolean, String, boolean, boolean)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
protected EntityType(
|
||||
TypeFactory.TypeScope scope,
|
||||
String entityName,
|
||||
String uniqueKeyPropertyName,
|
||||
boolean eager,
|
||||
boolean unwrapProxy) {
|
||||
this( scope, entityName, uniqueKeyPropertyName == null, uniqueKeyPropertyName, eager, unwrapProxy );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the requested entity type mapping.
|
||||
*
|
||||
* @param scope The type scope
|
||||
* @param entityName The name of the associated entity.
|
||||
* @param referenceToPrimaryKey True if association references a primary key.
|
||||
* @param uniqueKeyPropertyName The property-ref name, or null if we
|
||||
* reference the PK of the associated entity.
|
||||
* @param eager Is eager fetching enabled.
|
||||
* @param unwrapProxy Is unwrapping of proxies allowed for this association; unwrapping
|
||||
* says to return the "implementation target" of lazy prooxies; typically only possible
|
||||
* with lazy="no-proxy".
|
||||
*/
|
||||
protected EntityType(
|
||||
TypeFactory.TypeScope scope,
|
||||
String entityName,
|
||||
boolean referenceToPrimaryKey,
|
||||
String uniqueKeyPropertyName,
|
||||
boolean eager,
|
||||
boolean unwrapProxy) {
|
||||
|
@ -115,6 +141,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
|
|||
this.isEmbeddedInXML = true;
|
||||
this.eager = eager;
|
||||
this.unwrapProxy = unwrapProxy;
|
||||
this.referenceToPrimaryKey = referenceToPrimaryKey;
|
||||
}
|
||||
|
||||
protected TypeFactory.TypeScope scope() {
|
||||
|
@ -169,7 +196,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
|
|||
* @return True if this association reference the PK of the associated entity.
|
||||
*/
|
||||
public boolean isReferenceToPrimaryKey() {
|
||||
return uniqueKeyPropertyName==null;
|
||||
return referenceToPrimaryKey;
|
||||
}
|
||||
|
||||
public String getRHSUniqueKeyPropertyName() {
|
||||
|
@ -456,21 +483,16 @@ public abstract class EntityType extends AbstractType implements AssociationType
|
|||
return value;
|
||||
}
|
||||
|
||||
if ( value == null ) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
if ( isNull( owner, session ) ) {
|
||||
return null; //EARLY EXIT!
|
||||
}
|
||||
|
||||
if ( value != null && !isNull( owner, session ) ) {
|
||||
if ( isReferenceToPrimaryKey() ) {
|
||||
return resolveIdentifier( (Serializable) value, session );
|
||||
}
|
||||
else {
|
||||
else if ( uniqueKeyPropertyName != null ) {
|
||||
return loadByUniqueKey( getAssociatedEntityName(), uniqueKeyPropertyName, value, session );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Type getSemiResolvedType(SessionFactoryImplementor factory) {
|
||||
|
@ -482,7 +504,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
|
|||
return value;
|
||||
}
|
||||
|
||||
if ( isReferenceToPrimaryKey() ) {
|
||||
if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) {
|
||||
return ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session ); //tolerates nulls
|
||||
}
|
||||
else if ( value == null ) {
|
||||
|
@ -599,7 +621,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
|
|||
* or unique key property name.
|
||||
*/
|
||||
public final Type getIdentifierOrUniqueKeyType(Mapping factory) throws MappingException {
|
||||
if ( isReferenceToPrimaryKey() ) {
|
||||
if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) {
|
||||
return getIdentifierType(factory);
|
||||
}
|
||||
else {
|
||||
|
@ -621,7 +643,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
|
|||
*/
|
||||
public final String getIdentifierOrUniqueKeyPropertyName(Mapping factory)
|
||||
throws MappingException {
|
||||
if ( isReferenceToPrimaryKey() ) {
|
||||
if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) {
|
||||
return factory.getIdentifierPropertyName( getAssociatedEntityName() );
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -67,13 +67,12 @@ public class ManyToOneType extends EntityType {
|
|||
* @param lazy Should the association be handled lazily
|
||||
*/
|
||||
public ManyToOneType(TypeFactory.TypeScope scope, String referencedEntityName, boolean lazy) {
|
||||
this( scope, referencedEntityName, null, lazy, true, false, false, false );
|
||||
this( scope, referencedEntityName, true, null, lazy, true, false, false );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #ManyToOneType(TypeFactory.TypeScope, String, String, boolean, boolean, boolean, boolean ) } instead.
|
||||
* See Jira issue: <a href="https://hibernate.onjira.com/browse/HHH-7771">HHH-7771</a>
|
||||
* @deprecated Use {@link #ManyToOneType(TypeFactory.TypeScope, String, boolean, String, boolean, boolean, boolean, boolean ) } instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public ManyToOneType(
|
||||
|
@ -85,11 +84,14 @@ public class ManyToOneType extends EntityType {
|
|||
boolean isEmbeddedInXML,
|
||||
boolean ignoreNotFound,
|
||||
boolean isLogicalOneToOne) {
|
||||
super( scope, referencedEntityName, uniqueKeyPropertyName, !lazy, isEmbeddedInXML, unwrapProxy );
|
||||
this.ignoreNotFound = ignoreNotFound;
|
||||
this.isLogicalOneToOne = isLogicalOneToOne;
|
||||
this( scope, referencedEntityName, uniqueKeyPropertyName == null, uniqueKeyPropertyName, lazy, unwrapProxy, ignoreNotFound, isLogicalOneToOne );
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #ManyToOneType(TypeFactory.TypeScope, String, boolean, String, boolean, boolean, boolean, boolean ) } instead.
|
||||
* See Jira issue: <a href="https://hibernate.onjira.com/browse/HHH-7771">HHH-7771</a>
|
||||
*/
|
||||
@Deprecated
|
||||
public ManyToOneType(
|
||||
TypeFactory.TypeScope scope,
|
||||
String referencedEntityName,
|
||||
|
@ -98,7 +100,19 @@ public class ManyToOneType extends EntityType {
|
|||
boolean unwrapProxy,
|
||||
boolean ignoreNotFound,
|
||||
boolean isLogicalOneToOne) {
|
||||
super( scope, referencedEntityName, uniqueKeyPropertyName, !lazy, unwrapProxy );
|
||||
this( scope, referencedEntityName, uniqueKeyPropertyName == null, uniqueKeyPropertyName, lazy, unwrapProxy, ignoreNotFound, isLogicalOneToOne );
|
||||
}
|
||||
|
||||
public ManyToOneType(
|
||||
TypeFactory.TypeScope scope,
|
||||
String referencedEntityName,
|
||||
boolean referenceToPrimaryKey,
|
||||
String uniqueKeyPropertyName,
|
||||
boolean lazy,
|
||||
boolean unwrapProxy,
|
||||
boolean ignoreNotFound,
|
||||
boolean isLogicalOneToOne) {
|
||||
super( scope, referencedEntityName, referenceToPrimaryKey, uniqueKeyPropertyName, !lazy, unwrapProxy );
|
||||
this.ignoreNotFound = ignoreNotFound;
|
||||
this.isLogicalOneToOne = isLogicalOneToOne;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public class OneToOneType extends EntityType {
|
|||
private final String entityName;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #OneToOneType(TypeFactory.TypeScope, String, ForeignKeyDirection, String, boolean, boolean, String, String)}
|
||||
* @deprecated Use {@link #OneToOneType(TypeFactory.TypeScope, String, ForeignKeyDirection, boolean, String, boolean, boolean, String, String)}
|
||||
* instead.
|
||||
* See Jira issue: <a href="https://hibernate.onjira.com/browse/HHH-7771">HHH-7771</a>
|
||||
*/
|
||||
|
@ -63,12 +63,14 @@ public class OneToOneType extends EntityType {
|
|||
boolean isEmbeddedInXML,
|
||||
String entityName,
|
||||
String propertyName) {
|
||||
super( scope, referencedEntityName, uniqueKeyPropertyName, !lazy, isEmbeddedInXML, unwrapProxy );
|
||||
this.foreignKeyType = foreignKeyType;
|
||||
this.propertyName = propertyName;
|
||||
this.entityName = entityName;
|
||||
this( scope, referencedEntityName, foreignKeyType, uniqueKeyPropertyName == null, uniqueKeyPropertyName, lazy, unwrapProxy, entityName, propertyName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #OneToOneType(TypeFactory.TypeScope, String, ForeignKeyDirection, boolean, String, boolean, boolean, String, String)}
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public OneToOneType(
|
||||
TypeFactory.TypeScope scope,
|
||||
String referencedEntityName,
|
||||
|
@ -78,7 +80,20 @@ public class OneToOneType extends EntityType {
|
|||
boolean unwrapProxy,
|
||||
String entityName,
|
||||
String propertyName) {
|
||||
super( scope, referencedEntityName, uniqueKeyPropertyName, !lazy, unwrapProxy );
|
||||
this( scope, referencedEntityName, foreignKeyType, uniqueKeyPropertyName == null, uniqueKeyPropertyName, lazy, unwrapProxy, entityName, propertyName );
|
||||
}
|
||||
|
||||
public OneToOneType(
|
||||
TypeFactory.TypeScope scope,
|
||||
String referencedEntityName,
|
||||
ForeignKeyDirection foreignKeyType,
|
||||
boolean referenceToPrimaryKey,
|
||||
String uniqueKeyPropertyName,
|
||||
boolean lazy,
|
||||
boolean unwrapProxy,
|
||||
String entityName,
|
||||
String propertyName) {
|
||||
super( scope, referencedEntityName, referenceToPrimaryKey, uniqueKeyPropertyName, !lazy, unwrapProxy );
|
||||
this.foreignKeyType = foreignKeyType;
|
||||
this.propertyName = propertyName;
|
||||
this.entityName = entityName;
|
||||
|
|
21
hibernate-core/src/main/java/org/hibernate/type/SpecialOneToOneType.java
Executable file → Normal file
21
hibernate-core/src/main/java/org/hibernate/type/SpecialOneToOneType.java
Executable file → Normal file
|
@ -43,6 +43,10 @@ import org.hibernate.metamodel.relational.Size;
|
|||
*/
|
||||
public class SpecialOneToOneType extends OneToOneType {
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #SpecialOneToOneType(org.hibernate.type.TypeFactory.TypeScope, String, ForeignKeyDirection, boolean, String, boolean, boolean, String, String)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public SpecialOneToOneType(
|
||||
TypeFactory.TypeScope scope,
|
||||
String referencedEntityName,
|
||||
|
@ -52,14 +56,27 @@ public class SpecialOneToOneType extends OneToOneType {
|
|||
boolean unwrapProxy,
|
||||
String entityName,
|
||||
String propertyName) {
|
||||
this( scope, referencedEntityName, foreignKeyType, uniqueKeyPropertyName == null, uniqueKeyPropertyName, lazy, unwrapProxy, entityName, propertyName );
|
||||
}
|
||||
|
||||
public SpecialOneToOneType(
|
||||
TypeFactory.TypeScope scope,
|
||||
String referencedEntityName,
|
||||
ForeignKeyDirection foreignKeyType,
|
||||
boolean referenceToPrimaryKey,
|
||||
String uniqueKeyPropertyName,
|
||||
boolean lazy,
|
||||
boolean unwrapProxy,
|
||||
String entityName,
|
||||
String propertyName) {
|
||||
super(
|
||||
scope,
|
||||
referencedEntityName,
|
||||
foreignKeyType,
|
||||
foreignKeyType,
|
||||
referenceToPrimaryKey,
|
||||
uniqueKeyPropertyName,
|
||||
lazy,
|
||||
unwrapProxy,
|
||||
true,
|
||||
entityName,
|
||||
propertyName
|
||||
);
|
||||
|
|
|
@ -27,8 +27,6 @@ import java.io.Serializable;
|
|||
import java.util.Comparator;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.classic.Lifecycle;
|
||||
|
@ -39,6 +37,7 @@ import org.hibernate.tuple.component.ComponentMetamodel;
|
|||
import org.hibernate.usertype.CompositeUserType;
|
||||
import org.hibernate.usertype.ParameterizedType;
|
||||
import org.hibernate.usertype.UserType;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Used internally to build instances of {@link Type}, specifically it builds instances of
|
||||
|
@ -235,8 +234,7 @@ public final class TypeFactory implements Serializable {
|
|||
// one-to-one type builders ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #oneToOne(String, ForeignKeyDirection, String, boolean, boolean, String, String)}
|
||||
* instead.
|
||||
* @deprecated Use {@link #oneToOne(String, ForeignKeyDirection, String, boolean, boolean, String, String, boolean)} instead.
|
||||
* See Jira issue: <a href="https://hibernate.onjira.com/browse/HHH-7771">HHH-7771</a>
|
||||
*/
|
||||
@Deprecated
|
||||
|
@ -249,10 +247,14 @@ public final class TypeFactory implements Serializable {
|
|||
boolean isEmbeddedInXML,
|
||||
String entityName,
|
||||
String propertyName) {
|
||||
return new OneToOneType( typeScope, persistentClass, foreignKeyType, uniqueKeyPropertyName,
|
||||
lazy, unwrapProxy, isEmbeddedInXML, entityName, propertyName );
|
||||
return oneToOne( persistentClass, foreignKeyType, uniqueKeyPropertyName == null, uniqueKeyPropertyName, lazy, unwrapProxy, entityName,
|
||||
propertyName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #oneToOne(String, ForeignKeyDirection, String, boolean, boolean, String, String, boolean)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public EntityType oneToOne(
|
||||
String persistentClass,
|
||||
ForeignKeyDirection foreignKeyType,
|
||||
|
@ -261,10 +263,27 @@ public final class TypeFactory implements Serializable {
|
|||
boolean unwrapProxy,
|
||||
String entityName,
|
||||
String propertyName) {
|
||||
return new OneToOneType( typeScope, persistentClass, foreignKeyType, uniqueKeyPropertyName,
|
||||
lazy, unwrapProxy, entityName, propertyName );
|
||||
return oneToOne( persistentClass, foreignKeyType, uniqueKeyPropertyName == null, uniqueKeyPropertyName, lazy, unwrapProxy, entityName,
|
||||
propertyName );
|
||||
}
|
||||
|
||||
public EntityType oneToOne(
|
||||
String persistentClass,
|
||||
ForeignKeyDirection foreignKeyType,
|
||||
boolean referenceToPrimaryKey,
|
||||
String uniqueKeyPropertyName,
|
||||
boolean lazy,
|
||||
boolean unwrapProxy,
|
||||
String entityName,
|
||||
String propertyName) {
|
||||
return new OneToOneType( typeScope, persistentClass, foreignKeyType, referenceToPrimaryKey,
|
||||
uniqueKeyPropertyName, lazy, unwrapProxy, entityName, propertyName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #specialOneToOne(String, ForeignKeyDirection, String, boolean, boolean, String, String, boolean)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public EntityType specialOneToOne(
|
||||
String persistentClass,
|
||||
ForeignKeyDirection foreignKeyType,
|
||||
|
@ -273,8 +292,21 @@ public final class TypeFactory implements Serializable {
|
|||
boolean unwrapProxy,
|
||||
String entityName,
|
||||
String propertyName) {
|
||||
return new SpecialOneToOneType( typeScope, persistentClass, foreignKeyType, uniqueKeyPropertyName,
|
||||
lazy, unwrapProxy, entityName, propertyName );
|
||||
return specialOneToOne( persistentClass, foreignKeyType, uniqueKeyPropertyName == null, uniqueKeyPropertyName, lazy, unwrapProxy,
|
||||
entityName, propertyName );
|
||||
}
|
||||
|
||||
public EntityType specialOneToOne(
|
||||
String persistentClass,
|
||||
ForeignKeyDirection foreignKeyType,
|
||||
boolean referenceToPrimaryKey,
|
||||
String uniqueKeyPropertyName,
|
||||
boolean lazy,
|
||||
boolean unwrapProxy,
|
||||
String entityName,
|
||||
String propertyName) {
|
||||
return new SpecialOneToOneType( typeScope, persistentClass, foreignKeyType, referenceToPrimaryKey,
|
||||
uniqueKeyPropertyName, lazy, unwrapProxy, entityName, propertyName );
|
||||
}
|
||||
|
||||
|
||||
|
@ -289,8 +321,7 @@ public final class TypeFactory implements Serializable {
|
|||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #manyToOne(String, String, boolean, boolean, boolean, boolean)}
|
||||
* instead.
|
||||
* @deprecated Use {@link #manyToOne(String, boolean, String, boolean, boolean, boolean, boolean)} instead.
|
||||
* See Jira issue: <a href="https://hibernate.onjira.com/browse/HHH-7771">HHH-7771</a>
|
||||
*/
|
||||
@Deprecated
|
||||
|
@ -302,20 +333,28 @@ public final class TypeFactory implements Serializable {
|
|||
boolean isEmbeddedInXML,
|
||||
boolean ignoreNotFound,
|
||||
boolean isLogicalOneToOne) {
|
||||
return new ManyToOneType(
|
||||
typeScope,
|
||||
persistentClass,
|
||||
uniqueKeyPropertyName,
|
||||
lazy,
|
||||
unwrapProxy,
|
||||
isEmbeddedInXML,
|
||||
ignoreNotFound,
|
||||
isLogicalOneToOne
|
||||
);
|
||||
return manyToOne( persistentClass, uniqueKeyPropertyName == null, uniqueKeyPropertyName, lazy, unwrapProxy, ignoreNotFound,
|
||||
isLogicalOneToOne );
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #manyToOne(String, boolean, String, boolean, boolean, boolean, boolean)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public EntityType manyToOne(
|
||||
String persistentClass,
|
||||
String uniqueKeyPropertyName,
|
||||
boolean lazy,
|
||||
boolean unwrapProxy,
|
||||
boolean ignoreNotFound,
|
||||
boolean isLogicalOneToOne) {
|
||||
return manyToOne( persistentClass, uniqueKeyPropertyName == null, uniqueKeyPropertyName, lazy, unwrapProxy, ignoreNotFound,
|
||||
isLogicalOneToOne );
|
||||
}
|
||||
|
||||
public EntityType manyToOne(
|
||||
String persistentClass,
|
||||
boolean referenceToPrimaryKey,
|
||||
String uniqueKeyPropertyName,
|
||||
boolean lazy,
|
||||
boolean unwrapProxy,
|
||||
|
@ -324,6 +363,7 @@ public final class TypeFactory implements Serializable {
|
|||
return new ManyToOneType(
|
||||
typeScope,
|
||||
persistentClass,
|
||||
referenceToPrimaryKey,
|
||||
uniqueKeyPropertyName,
|
||||
lazy,
|
||||
unwrapProxy,
|
||||
|
|
|
@ -27,14 +27,13 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
public class OneToOneWithDerivedIdentityTest extends BaseCoreFunctionalTestCase {
|
||||
@Test
|
||||
@FailureExpected(jiraKey = "HHH-5695")
|
||||
@TestForIssue(jiraKey = "HHH-5695")
|
||||
public void testInsertFooAndBarWithDerivedId() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
|
|
Loading…
Reference in New Issue