Skip to content

Commit

Permalink
HHH-7108 HHH-6608
Browse files Browse the repository at this point in the history
  • Loading branch information
stliu committed Aug 7, 2012
1 parent 45118e7 commit d0e13b6
Show file tree
Hide file tree
Showing 18 changed files with 993 additions and 102 deletions.
Expand Up @@ -2496,6 +2496,7 @@ private static void bindIdClass(
value.setPersistentClassName( persistentClassName );
value.setMappings( mappings );
value.setType( inferredData.getProperty(), inferredData.getClassOrElement() );
value.setAccessType( propertyAccessor );
id = value.make();
}
rootClass.setIdentifier( id );
Expand Down
16 changes: 8 additions & 8 deletions hibernate-core/src/main/java/org/hibernate/cfg/BinderHelper.java
Expand Up @@ -268,15 +268,15 @@ public static void createSyntheticPropertyReference(
*/
StringBuilder propertyNameBuffer = new StringBuilder( "_" );
propertyNameBuffer.append( associatedClass.getEntityName().replace( '.', '_' ) );
propertyNameBuffer.append( "_" ).append( columns[0].getPropertyName() );
propertyNameBuffer.append( "_" ).append( columns[0].getPropertyName().replace( '.', '_' ) );
String syntheticPropertyName = propertyNameBuffer.toString();
//find properties associated to a certain column
Object columnOwner = findColumnOwner( ownerEntity, columns[0].getReferencedColumn(), mappings );
List<Property> properties = findPropertiesByColumns( columnOwner, columns, mappings );
//create an embeddable component
Property synthProp = null;
Property synthProp = null;
if ( properties != null ) {
//todo how about properties.size() == 1, this should be much simpler
//todo how about properties.size() == 1, this should be much simpler
Component embeddedComp = columnOwner instanceof PersistentClass ?
new Component( mappings, (PersistentClass) columnOwner ) :
new Component( mappings, (Join) columnOwner );
Expand All @@ -290,8 +290,8 @@ public static void createSyntheticPropertyReference(
clone.setNaturalIdentifier( false );
clone.setGeneration( property.getGeneration() );
embeddedComp.addProperty( clone );
}
synthProp = new SyntheticProperty();
}
synthProp = new SyntheticProperty();
synthProp.setName( syntheticPropertyName );
synthProp.setNodeName( syntheticPropertyName );
synthProp.setPersistentClass( ownerEntity );
Expand All @@ -300,9 +300,9 @@ public static void createSyntheticPropertyReference(
synthProp.setValue( embeddedComp );
synthProp.setPropertyAccessorName( "embedded" );
ownerEntity.addProperty( synthProp );
//make it unique
//make it unique
TableBinder.createUniqueConstraint( embeddedComp );
}
}
else {
//TODO use a ToOne type doing a second select
StringBuilder columnsList = new StringBuilder();
Expand Down Expand Up @@ -830,7 +830,7 @@ public static Map<String,String> toAliasTableMap(SqlFragmentAlias[] aliases){
for (int i = 0; i < aliases.length; i++){
if (StringHelper.isNotEmpty(aliases[i].table())){
ret.put(aliases[i].alias(), aliases[i].table());
}
}
}
return ret;
}
Expand Down
Expand Up @@ -1289,6 +1289,8 @@ else if ( owner.getIdentifierMapper() != null && owner.getIdentifierMapper().get
}
elementBinder.setColumns( elementColumns );
elementBinder.setType( property, elementClass );
elementBinder.setPersistentClassName( propertyHolder.getEntityName() );
elementBinder.setAccessType( accessType );
collValue.setElement( elementBinder.make() );
String orderBy = adjustUserSuppliedValueCollectionOrderingFragment( hqlOrderBy );
if ( orderBy != null ) {
Expand Down Expand Up @@ -1439,4 +1441,4 @@ public void setMapKeyManyToManyColumns(Ejb3JoinColumn[] mapJoinColumns) {
public void setLocalGenerators(HashMap<String, IdGenerator> localGenerators) {
this.localGenerators = localGenerators;
}
}
}
Expand Up @@ -210,26 +210,25 @@ private void bindKeyFromAssociationTable(
}
}

PersistentClass owner = mapValue.getOwner();
AccessType accessType;
// FIXME support @Access for collection of elements
// String accessType = access != null ? access.value() : null;
if ( owner.getIdentifierProperty() != null ) {
accessType = owner.getIdentifierProperty().getPropertyAccessorName().equals( "property" ) ? AccessType.PROPERTY
: AccessType.FIELD;
}
else if ( owner.getIdentifierMapper() != null && owner.getIdentifierMapper().getPropertySpan() > 0 ) {
Property prop = (Property) owner.getIdentifierMapper().getPropertyIterator().next();
accessType = prop.getPropertyAccessorName().equals( "property" ) ? AccessType.PROPERTY
: AccessType.FIELD;
}
else {
throw new AssertionFailure( "Unable to guess collection property accessor name" );
}

if ( AnnotatedClassType.EMBEDDABLE.equals( classType ) ) {
EntityBinder entityBinder = new EntityBinder();
PersistentClass owner = mapValue.getOwner();
boolean isPropertyAnnotated;
//FIXME support @Access for collection of elements
//String accessType = access != null ? access.value() : null;
if ( owner.getIdentifierProperty() != null ) {
isPropertyAnnotated = owner.getIdentifierProperty()
.getPropertyAccessorName()
.equals( "property" );
}
else
if ( owner.getIdentifierMapper() != null && owner.getIdentifierMapper().getPropertySpan() > 0 ) {
Property prop = (Property) owner.getIdentifierMapper().getPropertyIterator().next();
isPropertyAnnotated = prop.getPropertyAccessorName().equals( "property" );
}
else {
throw new AssertionFailure( "Unable to guess collection property accessor name" );
}


PropertyData inferredData;
if ( isHibernateExtensionMapping() ) {
Expand All @@ -242,7 +241,7 @@ private void bindKeyFromAssociationTable(

//TODO be smart with isNullable
Component component = AnnotationBinder.fillComponent(
holder, inferredData, isPropertyAnnotated ? AccessType.PROPERTY : AccessType.FIELD, true,
holder, inferredData, accessType, true,
entityBinder, false, false,
true, mappings, inheritanceStatePerClass
);
Expand Down Expand Up @@ -285,6 +284,8 @@ private void bindKeyFromAssociationTable(
else {
elementBinder.setType( property, elementClass );
}
elementBinder.setPersistentClassName( propertyHolder.getEntityName() );
elementBinder.setAccessType( accessType );
mapValue.setIndex( elementBinder.make() );
}
}
Expand Down
Expand Up @@ -188,6 +188,7 @@ private Property makePropertyAndValue() {
simpleValueBinder.setType( property, returnedClass );
simpleValueBinder.setMappings( mappings );
simpleValueBinder.setReferencedEntityName( referencedEntityName );
simpleValueBinder.setAccessType( accessType );
SimpleValue propertyValue = simpleValueBinder.make();
setValue( propertyValue );
return makeProperty();
Expand Down

0 comments on commit d0e13b6

Please sign in to comment.