[hibernate-commits] Hibernate SVN: r10321 - in trunk/HibernateExt: ejb/src/test/org/hibernate/ejb/test/pack ejb/src/test/org/hibernate/ejb/test/pack/explicitpar ejb/src/test-resources/explicitpar/META-INF metadata/src/java/org/hibernate/cfg metadata/src/java/org/hibernate/cfg/annotations metadata/src/test/org/hibernate/test/annotations/idmanytoone
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Wed Aug 23 18:01:11 EDT 2006
Author: epbernard
Date: 2006-08-23 18:00:58 -0400 (Wed, 23 Aug 2006)
New Revision: 10321
Added:
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/explicitpar/
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/explicitpar/Washer.java
Modified:
trunk/HibernateExt/ejb/src/test-resources/explicitpar/META-INF/persistence.xml
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/ClassPropertyHolder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/CollectionPropertyHolder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/ComponentPropertyHolder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/FkSecondPass.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/OneToOneSecondPass.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/PropertyHolder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/TableBinder.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/Card.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/CardField.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/CardKey.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/IdManyToOne.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/Project.java
Log:
ANN-381 properly sort collection tables and ignore many to one not related to id properties
Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/explicitpar/Washer.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/explicitpar/Washer.java 2006-08-23 21:57:26 UTC (rev 10320)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/pack/explicitpar/Washer.java 2006-08-23 22:00:58 UTC (rev 10321)
@@ -0,0 +1,12 @@
+//$Id: $
+package org.hibernate.ejb.test.pack.explicitpar;
+
+import javax.persistence.Entity;
+
+/**
+ * @author Emmanuel Bernard
+ */
+ at Entity
+public class Washer {
+ //No @id so picking it up should fail
+}
Modified: trunk/HibernateExt/ejb/src/test-resources/explicitpar/META-INF/persistence.xml
===================================================================
--- trunk/HibernateExt/ejb/src/test-resources/explicitpar/META-INF/persistence.xml 2006-08-23 21:57:26 UTC (rev 10320)
+++ trunk/HibernateExt/ejb/src/test-resources/explicitpar/META-INF/persistence.xml 2006-08-23 22:00:58 UTC (rev 10321)
@@ -9,6 +9,7 @@
<class>org.hibernate.ejb.test.Distributor</class>
<class>org.hibernate.ejb.test.Item</class>
<class>org.hibernate.ejb.test</class>
+ <exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2006-08-23 21:57:26 UTC (rev 10320)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2006-08-23 22:00:58 UTC (rev 10321)
@@ -1765,6 +1765,7 @@
new FkSecondPass(
value, columns,
!optional && unique, //cannot have nullabe and unique on certain DBs like Derby
+ propertyHolder.getEntityOwnerClassName(),
path, mappings
)
);
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2006-08-23 21:57:26 UTC (rev 10320)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2006-08-23 22:00:58 UTC (rev 10321)
@@ -14,6 +14,9 @@
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
+import java.util.TreeSet;
+import java.util.SortedSet;
+import java.util.Comparator;
import javax.persistence.Entity;
import javax.persistence.MappedSuperclass;
@@ -26,6 +29,7 @@
import org.dom4j.io.SAXReader;
import org.hibernate.AnnotationException;
import org.hibernate.MappingException;
+import org.hibernate.AssertionFailure;
import org.hibernate.cfg.annotations.Version;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Join;
@@ -235,10 +239,10 @@
for ( XClass clazz : annotatedClasses ) {
if ( clazz.isAnnotationPresent( Entity.class ) ) {
annotatedClassEntities.put( clazz.getName(), clazz );
- tempAnnotatedClasses.add(clazz);
+ tempAnnotatedClasses.add( clazz );
}
- else if (clazz.isAnnotationPresent( MappedSuperclass.class ) ) {
- tempAnnotatedClasses.add(clazz);
+ else if ( clazz.isAnnotationPresent( MappedSuperclass.class ) ) {
+ tempAnnotatedClasses.add( clazz );
}
//only keep MappedSuperclasses and Entity in this list
}
@@ -284,7 +288,7 @@
SecondPass sp = (SecondPass) iter.next();
//do the second pass of fk before the others and remove them
if ( sp instanceof CreateKeySecondPass ) {
- sp.doSecondPass( classes );
+ sp.doSecondPass( classes );
iter.remove();
}
}
@@ -328,58 +332,100 @@
* graph circularity (ie PK made of a many to one linking to
* an entity having a PK made of a ManyToOne ...
*/
- Set fkSecondPasses = new HashSet();
+ SortedSet<FkSecondPass> fkSecondPasses = new TreeSet<FkSecondPass>(
+ new Comparator() {
+ //The comparator implementation has to respect the compare=0 => equals() = true for sets
+ public int compare(Object o1, Object o2) {
+ if (! (o1 instanceof FkSecondPass && o2 instanceof FkSecondPass) ) {
+ throw new AssertionFailure("comparint FkSecondPass with non FkSecondPass");
+ }
+ FkSecondPass f1 = (FkSecondPass) o1;
+ FkSecondPass f2 = (FkSecondPass) o2;
+ int compare = f1.getValue().getTable().getQuotedName().compareTo(
+ f2.getValue().getTable().getQuotedName()
+ );
+ if (compare == 0) {
+ //same table, we still need to differenciate true equality
+ if ( f1.hashCode() < f2.hashCode() ) {
+ compare = -1;
+ }
+ else if ( f1.hashCode() == f2.hashCode() ) {
+ compare = 0;
+ }
+ else {
+ compare = 1;
+ }
+ }
+ return compare;
+ }
+ }
+ );
while ( iter.hasNext() ) {
SecondPass sp = (SecondPass) iter.next();
//do the second pass of fk before the others and remove them
if ( sp instanceof FkSecondPass ) {
- fkSecondPasses.add(sp);
+ fkSecondPasses.add( (FkSecondPass) sp );
iter.remove();
}
}
- if (fkSecondPasses.size() > 0) {
+ if ( fkSecondPasses.size() > 0 ) {
Map<String, Set<String>> isADependencyOf = new HashMap<String, Set<String>>();
List orderedFkSecondPasses = new ArrayList( fkSecondPasses.size() );
+ List endOfQueueFkSecondPasses = new ArrayList( fkSecondPasses.size() );
List orderedTable = new ArrayList( fkSecondPasses.size() );
Iterator it = fkSecondPasses.iterator();
while ( it.hasNext() ) {
FkSecondPass sp = (FkSecondPass) it.next();
String referenceEntityName = sp.getValue().getReferencedEntityName();
- String dependentTable = getClassMapping( referenceEntityName ).getTable().getQuotedName();
- if ( ! isADependencyOf.containsKey( dependentTable ) ) {
- isADependencyOf.put( dependentTable, new HashSet<String>() );
- }
- String table = sp.getValue().getTable().getQuotedName();
- isADependencyOf.get( dependentTable ).add( table );
- int beAfter = orderedTable.indexOf( dependentTable );
- int beBefore = orderedFkSecondPasses.size();
- Set<String> dependencies = isADependencyOf.get( table );
- if (dependencies != null) {
- for ( String tableDep : dependencies ) {
- //for each declared dependency take the lowest index
- int index = orderedTable.indexOf( tableDep );
- //index = -1 when we have a self dependency
- beBefore = index != -1 && index < beBefore ? index : beBefore;
+ PersistentClass classMapping = getClassMapping( referenceEntityName );
+ if ( sp.isInPrimaryKey() ) {
+ String dependentTable = classMapping.getTable().getQuotedName();
+ if ( ! isADependencyOf.containsKey( dependentTable ) ) {
+ isADependencyOf.put( dependentTable, new HashSet<String>() );
}
+ String table = sp.getValue().getTable().getQuotedName();
+ isADependencyOf.get( dependentTable ).add( table );
+ int beAfter = orderedTable.indexOf( dependentTable );
+ int beBefore = orderedFkSecondPasses.size();
+ Set<String> dependencies = isADependencyOf.get( table );
+ if ( dependencies != null ) {
+ for ( String tableDep : dependencies ) {
+ //for each declared dependency take the lowest index
+ int index = orderedTable.indexOf( tableDep );
+ //index = -1 when we have a self dependency
+ beBefore = index != -1 && index < beBefore ? index : beBefore;
+ }
+ }
+ int currentIndex = orderedTable.indexOf( table );
+ if ( beBefore < beAfter ||
+ ( currentIndex != -1 && ( currentIndex < beAfter || currentIndex > beBefore ) )
+ ) {
+ StringBuilder sb = new StringBuilder(
+ "Foreign key circularity dependency involving the following tables: "
+ );
+ sb.append( table );
+ if ( beAfter > -1 ) sb.append( ", " ).append( dependentTable );
+ if ( beBefore < orderedFkSecondPasses.size() ) {
+ sb.append( ", " ).append( orderedTable.get( beBefore ) );
+ }
+ throw new AnnotationException( sb.toString() );
+ }
+ currentIndex = currentIndex == -1 ? beBefore : currentIndex;
+ orderedTable.add( currentIndex, table );
+ orderedFkSecondPasses.add( currentIndex, sp );
}
- int currentIndex = orderedTable.indexOf( table );
- if (beBefore < beAfter ||
- (currentIndex != -1 && ( currentIndex < beAfter || currentIndex > beBefore ) )
- ) {
- StringBuilder sb = new StringBuilder("Foreign key circularity dependency involving the following tables: ");
- sb.append( table );
- if (beAfter > -1) sb.append(", ").append( dependentTable );
- if ( beBefore < orderedFkSecondPasses.size() ) sb.append(", ").append( orderedTable.get(beBefore) );
- throw new AnnotationException( sb.toString() );
+ else {
+ endOfQueueFkSecondPasses.add( sp );
}
- currentIndex = currentIndex == -1 ? beBefore : currentIndex;
- orderedTable.add( currentIndex, table );
- orderedFkSecondPasses.add( currentIndex, sp );
}
it = orderedFkSecondPasses.listIterator();
while ( it.hasNext() ) {
( (SecondPass) it.next() ).doSecondPass( classes );
}
+ it = endOfQueueFkSecondPasses.listIterator();
+ while ( it.hasNext() ) {
+ ( (SecondPass) it.next() ).doSecondPass( classes );
+ }
}
}
@@ -537,7 +583,7 @@
}
else {
List<String> classnames = ( (JavaXFactory) reflectionManager ).getXMLContext().addDocument( doc );
- for (String classname : classnames) {
+ for ( String classname : classnames ) {
try {
annotatedClasses.add( reflectionManager.classForName( classname, this.getClass() ) );
}
@@ -610,8 +656,10 @@
saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true );
//saxReader.setFeature( "http://apache.org/xml/features/validation/dynamic", true );
//set the default schema locators
- saxReader.setProperty( "http://apache.org/xml/properties/schema/external-schemaLocation",
- "http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd");
+ saxReader.setProperty(
+ "http://apache.org/xml/properties/schema/external-schemaLocation",
+ "http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
+ );
}
catch (SAXException e) {
saxReader.setValidation( false );
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/ClassPropertyHolder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/ClassPropertyHolder.java 2006-08-23 21:57:26 UTC (rev 10320)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/ClassPropertyHolder.java 2006-08-23 22:00:58 UTC (rev 10321)
@@ -94,6 +94,10 @@
return persistentClass.getClassName();
}
+ public String getEntityOwnerClassName() {
+ return getClassName();
+ }
+
public Table getTable() {
return persistentClass.getTable();
}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/CollectionPropertyHolder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/CollectionPropertyHolder.java 2006-08-23 21:57:26 UTC (rev 10320)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/CollectionPropertyHolder.java 2006-08-23 22:00:58 UTC (rev 10321)
@@ -32,6 +32,10 @@
throw new AssertionFailure( "Collection property holder does not have a class name" );
}
+ public String getEntityOwnerClassName() {
+ return null;
+ }
+
public Table getTable() {
return collection.getCollectionTable();
}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/ComponentPropertyHolder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/ComponentPropertyHolder.java 2006-08-23 21:57:26 UTC (rev 10320)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/ComponentPropertyHolder.java 2006-08-23 22:00:58 UTC (rev 10321)
@@ -67,6 +67,10 @@
return component.getComponentClassName();
}
+ public String getEntityOwnerClassName() {
+ return component.getOwner().getClassName();
+ }
+
public Table getTable() {
return component.getTable();
}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/FkSecondPass.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/FkSecondPass.java 2006-08-23 21:57:26 UTC (rev 10320)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/FkSecondPass.java 2006-08-23 22:00:58 UTC (rev 10321)
@@ -4,11 +4,13 @@
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.MappingException;
+import org.hibernate.util.StringHelper;
import org.hibernate.cfg.annotations.TableBinder;
import org.hibernate.mapping.ManyToOne;
import org.hibernate.mapping.OneToOne;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.ToOne;
+import org.hibernate.mapping.Property;
/**
* Enable a proper set of the FK columns in respect with the id column order
@@ -23,26 +25,39 @@
private boolean unique;
private ExtendedMappings mappings;
private String path;
+ private String entityClassName;
- FkSecondPass(ToOne value, Ejb3JoinColumn[] columns, boolean unique, String path, ExtendedMappings mappings) {
+ FkSecondPass(
+ ToOne value, Ejb3JoinColumn[] columns, boolean unique, String entityClassName, String path, ExtendedMappings mappings
+ ) {
this.mappings = mappings;
this.value = value;
this.columns = columns;
this.unique = unique;
- this.path = path;
+ this.entityClassName = entityClassName;
+ this.path = entityClassName != null ? path.substring( entityClassName.length() + 1 ) : path;
}
public ToOne getValue() {
return value;
}
+ public boolean isInPrimaryKey() {
+ if (entityClassName == null) return false;
+ Property property = mappings.getClass( entityClassName ).getIdentifierProperty();
+ return property != null && path != null && path.startsWith( property.getName() );
+ }
+
public void doSecondPass(java.util.Map persistentClasses) throws MappingException {
if ( value instanceof ManyToOne ) {
ManyToOne manyToOne = (ManyToOne) value;
PersistentClass ref = (PersistentClass) persistentClasses.get( manyToOne.getReferencedEntityName() );
if ( ref == null ) {
throw new AnnotationException(
- "@OneToOne or @ManyToOne on " + path + " references an unknown entity: " + manyToOne.getReferencedEntityName()
+ "@OneToOne or @ManyToOne on "
+ + StringHelper.qualify(entityClassName, path)
+ + " references an unknown entity: "
+ + manyToOne.getReferencedEntityName()
);
}
BinderHelper.createSyntheticPropertyReference( columns, ref, null, manyToOne, false, mappings );
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/OneToOneSecondPass.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/OneToOneSecondPass.java 2006-08-23 21:57:26 UTC (rev 10320)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/OneToOneSecondPass.java 2006-08-23 22:00:58 UTC (rev 10321)
@@ -105,6 +105,7 @@
( new FkSecondPass(
value, joinColumns,
!optional, //cannot have nullabe and unique on certain DBs
+ propertyHolder.getEntityOwnerClassName(),
path, mappings
) ).doSecondPass( persistentClasses );
//no column associated since its a one to one
@@ -122,7 +123,7 @@
if ( otherSide == null ) {
throw new MappingException( "Unable to find entity: " + value.getReferencedEntityName() );
}
- otherSideProperty = otherSide.getProperty( mappedBy );
+ otherSideProperty = otherSide.getRecursiveProperty( mappedBy );
}
catch (MappingException e) {
throw new AnnotationException(
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/PropertyHolder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/PropertyHolder.java 2006-08-23 21:57:26 UTC (rev 10320)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/PropertyHolder.java 2006-08-23 22:00:58 UTC (rev 10321)
@@ -18,6 +18,8 @@
public interface PropertyHolder {
String getClassName();
+ String getEntityOwnerClassName();
+
Table getTable();
void addProperty(Property prop);
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2006-08-23 21:57:26 UTC (rev 10320)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2006-08-23 22:00:58 UTC (rev 10321)
@@ -833,7 +833,7 @@
}
else {
keyVal = (KeyValue) collValue.getOwner()
- .getProperty( propRef )
+ .getRecursiveProperty( propRef )
.getValue();
}
DependantValue key = new DependantValue( collValue.getCollectionTable(), keyVal );
@@ -909,7 +909,7 @@
}
Property otherSideProperty;
try {
- otherSideProperty = collectionEntity.getProperty( joinColumns[0].getMappedBy() );
+ otherSideProperty = collectionEntity.getRecursiveProperty( joinColumns[0].getMappedBy() );
}
catch (MappingException e) {
StringBuilder error = new StringBuilder( 80 );
@@ -1148,7 +1148,7 @@
) {
final String mappedBy = columns[0].getMappedBy();
if ( StringHelper.isNotEmpty( mappedBy ) ) {
- final Property property = referencedEntity.getProperty( mappedBy );
+ final Property property = referencedEntity.getRecursiveProperty( mappedBy );
Iterator mappedByColumns;
if ( property.getValue() instanceof Collection ) {
mappedByColumns = ( (Collection) property.getValue() ).getKey().getColumnIterator();
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java 2006-08-23 21:57:26 UTC (rev 10320)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java 2006-08-23 22:00:58 UTC (rev 10321)
@@ -240,7 +240,7 @@
else if ( element instanceof DependantValue ) {
//TODO this never happen I think
if ( propertyName != null ) {
- Collection coll = (Collection) associatedClass.getProperty( propertyName )
+ Collection coll = (Collection) associatedClass.getRecursiveProperty( propertyName )
.getValue();
referencedPropertyName = collection.getReferencedPropertyName();
}
@@ -255,7 +255,7 @@
referencedEntityColumns = associatedClass.getIdentifier().getColumnIterator();
}
else {
- Property referencedProperty = associatedClass.getProperty( referencedPropertyName );
+ Property referencedProperty = associatedClass.getRecursiveProperty( referencedPropertyName );
table = referencedProperty.getValue().getTable();
referencedEntityColumns = referencedProperty.getColumnIterator();
}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/TableBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/TableBinder.java 2006-08-23 21:57:26 UTC (rev 10320)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/TableBinder.java 2006-08-23 22:00:58 UTC (rev 10321)
@@ -166,7 +166,7 @@
);
}
- final Property property = associatedClass.getProperty( columns[0].getMappedBy() );
+ final Property property = associatedClass.getRecursiveProperty( columns[0].getMappedBy() );
Iterator mappedByColumns;
if ( property.getValue() instanceof Collection ) {
Collection collection = ( (Collection) property.getValue() );
@@ -217,7 +217,7 @@
else if ( value instanceof DependantValue ) {
String propertyName = columns[0].getPropertyName();
if ( propertyName != null ) {
- Collection collection = (Collection) referencedEntity.getProperty( propertyName )
+ Collection collection = (Collection) referencedEntity.getRecursiveProperty( propertyName )
.getValue();
referencedPropertyName = collection.getReferencedPropertyName();
}
@@ -237,7 +237,7 @@
"No property ref found while expected"
);
}
- Property synthProp = referencedEntity.getProperty( referencedPropertyName );
+ Property synthProp = referencedEntity.getRecursiveProperty( referencedPropertyName );
if ( synthProp == null ) {
throw new AssertionFailure(
"Cannot find synthProp: " + referencedEntity.getEntityName() + "." + referencedPropertyName
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/Card.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/Card.java 2006-08-23 21:57:26 UTC (rev 10320)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/Card.java 2006-08-23 22:00:58 UTC (rev 10321)
@@ -2,10 +2,14 @@
package org.hibernate.test.annotations.idmanytoone;
import java.io.Serializable;
+import java.util.Set;
+import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.Id;
-import javax.persistence.Embeddable;
import javax.persistence.ManyToOne;
+import javax.persistence.CascadeType;
+import javax.persistence.FetchType;
+import javax.persistence.OneToMany;
/**
* @author Emmanuel Bernard
@@ -16,14 +20,51 @@
@Id
private CardPrimaryKey primaryKey = new CardPrimaryKey();
+ @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "primaryKey.card")
+ private Set<CardField> fields;
+
+ @ManyToOne
+ private CardField mainCardField;
+
@Embeddable
- private class CardPrimaryKey implements Serializable {
+ public static class CardPrimaryKey implements Serializable {
+ public CardPrimaryKey() {}
+
@ManyToOne(optional = false)
private Project project;
- //An other @ManyToOne is also present in the real model
- //The problem still occurs even when i remove this relation, it was no use to kept it for describe the problem
+ public Project getProject() {
+ return project;
+ }
+ public void setProject(Project project) {
+ this.project = project;
+ }
+
}
+
+ public Set<CardField> getFields() {
+ return fields;
+ }
+
+ public void setFields(Set<CardField> fields) {
+ this.fields = fields;
+ }
+
+ public CardPrimaryKey getPrimaryKey() {
+ return primaryKey;
+ }
+
+ public void setPrimaryKey(CardPrimaryKey primaryKey) {
+ this.primaryKey = primaryKey;
+ }
+
+ public CardField getMainCardField() {
+ return mainCardField;
+ }
+
+ public void setMainCardField(CardField mainCardField) {
+ this.mainCardField = mainCardField;
+ }
}
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/CardField.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/CardField.java 2006-08-23 21:57:26 UTC (rev 10320)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/CardField.java 2006-08-23 22:00:58 UTC (rev 10321)
@@ -20,13 +20,45 @@
private Card cardtmp;
@Embeddable
- private class PrimaryKey implements Serializable {
+ public static class PrimaryKey implements Serializable {
@ManyToOne(optional = false)
private Card card;
@ManyToOne(optional = false)
private CardKey key;
+
+ public Card getCard() {
+ return card;
+ }
+
+ public void setCard(Card card) {
+ this.card = card;
+ }
+
+ public CardKey getKey() {
+ return key;
+ }
+
+ public void setKey(CardKey key) {
+ this.key = key;
+ }
}
+
+ public Card getCardtmp() {
+ return cardtmp;
+ }
+
+ public void setCardtmp(Card cardtmp) {
+ this.cardtmp = cardtmp;
+ }
+
+ public PrimaryKey getPrimaryKey() {
+ return primaryKey;
+ }
+
+ public void setPrimaryKey(PrimaryKey primaryKey) {
+ this.primaryKey = primaryKey;
+ }
}
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/CardKey.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/CardKey.java 2006-08-23 21:57:26 UTC (rev 10320)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/CardKey.java 2006-08-23 22:00:58 UTC (rev 10321)
@@ -13,4 +13,12 @@
@Id
@GeneratedValue
private int id;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
}
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/IdManyToOne.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/IdManyToOne.java 2006-08-23 21:57:26 UTC (rev 10320)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/IdManyToOne.java 2006-08-23 22:00:58 UTC (rev 10321)
@@ -2,6 +2,7 @@
package org.hibernate.test.annotations.idmanytoone;
import org.hibernate.Session;
+import org.hibernate.Transaction;
import org.hibernate.test.annotations.TestCase;
/**
@@ -14,6 +15,30 @@
s.close();
}
+ public void getBiDirOneToManyInId() throws Exception {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ CardKey key = new CardKey();
+ s.persist( key );
+ Project project = new Project();
+ s.persist( project );
+ Card card = new Card();
+ card.getPrimaryKey().setProject( project );
+ s.persist( card );
+ CardField field = new CardField();
+ field.getPrimaryKey().setKey( key );
+ field.getPrimaryKey().setCard( card );
+ s.persist( field );
+ card.setMainCardField( field );
+ s.flush();
+ s.clear();
+ card = (Card) s.createQuery( "from Card c").list().get(0);
+ assertEquals( 1, card.getFields().size() );
+ assertEquals( card.getMainCardField(), card.getFields().iterator().next() );
+ tx.rollback();
+ s.close();
+ }
+
protected Class[] getMappings() {
return new Class[] {
CardKey.class,
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/Project.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/Project.java 2006-08-23 21:57:26 UTC (rev 10320)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/Project.java 2006-08-23 22:00:58 UTC (rev 10321)
@@ -14,4 +14,12 @@
@Id
@GeneratedValue
private int id;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
}
More information about the hibernate-commits
mailing list