Author: epbernard
Date: 2009-07-20 19:24:38 -0400 (Mon, 20 Jul 2009)
New Revision: 17171
Modified:
core/trunk/annotations/pom.xml
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/array/Contest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/Screen.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java
Log:
EJB-450 implement @CollectionTable for @ElementCollection
Modified: core/trunk/annotations/pom.xml
===================================================================
--- core/trunk/annotations/pom.xml 2009-07-20 21:43:17 UTC (rev 17170)
+++ core/trunk/annotations/pom.xml 2009-07-20 23:24:38 UTC (rev 17171)
@@ -62,7 +62,7 @@
<dependency>
<groupId>org.hibernate.java-persistence</groupId>
<artifactId>jpa-api</artifactId>
- <version>2.0.pfd-SNAPSHOT</version>
+ <version>2.0.Beta-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
@@ -83,7 +83,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
- <version>4.0.0.Beta2-SNAPSHOT</version>
+ <version>4.0.0.Beta3-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
---
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2009-07-20
21:43:17 UTC (rev 17170)
+++
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2009-07-20
23:24:38 UTC (rev 17171)
@@ -71,6 +71,8 @@
import javax.persistence.Transient;
import javax.persistence.Version;
import javax.persistence.ElementCollection;
+import javax.persistence.CollectionTable;
+import javax.persistence.UniqueConstraint;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
@@ -1170,9 +1172,10 @@
return;
}
- //process @JoinColumn(s) before @Column(s) to handle collection of elements properly
+ //process @JoinColumn(s) before @Column(s) to handle collection of entities properly
{
JoinColumn[] anns = null;
+
if ( property.isAnnotationPresent( JoinColumn.class ) ) {
anns = new JoinColumn[] { property.getAnnotation( JoinColumn.class ) };
}
@@ -1467,7 +1470,6 @@
org.hibernate.annotations.IndexColumn indexAnn = property.getAnnotation(
org.hibernate.annotations.IndexColumn.class
);
- JoinTable assocTable = property.getAnnotation( JoinTable.class );
IndexColumn indexColumn = IndexColumn.buildColumnFromAnnotation(
indexAnn, propertyHolder, inferredData, mappings
@@ -1626,8 +1628,9 @@
collectionBinder.setOneToMany( false );
}
collectionBinder.setMappedBy( mappedBy );
+
bindJoinedTableAssociation(
- assocTable, mappings, entityBinder, collectionBinder, propertyHolder, inferredData,
mappedBy
+ property, mappings, entityBinder, collectionBinder, propertyHolder, inferredData,
mappedBy
);
OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class );
@@ -1735,41 +1738,53 @@
//TODO move that to collection binder?
private static void bindJoinedTableAssociation(
- JoinTable joinTableAnn, ExtendedMappings mappings, EntityBinder entityBinder,
+ XProperty property, ExtendedMappings mappings, EntityBinder entityBinder,
CollectionBinder collectionBinder, PropertyHolder propertyHolder, PropertyData
inferredData,
String mappedBy
) {
TableBinder associationTableBinder = new TableBinder();
JoinColumn[] annJoins;
JoinColumn[] annInverseJoins;
- if ( joinTableAnn != null ) {
- collectionBinder.setExplicitAssociationTable( true );
- if ( !BinderHelper.isDefault( joinTableAnn.schema() ) )
- associationTableBinder.setSchema( joinTableAnn.schema() );
- if ( !BinderHelper.isDefault( joinTableAnn.catalog() ) )
- associationTableBinder.setCatalog( joinTableAnn.catalog() );
- if ( !BinderHelper.isDefault( joinTableAnn.name() ) ) associationTableBinder.setName(
joinTableAnn.name() );
- associationTableBinder.setUniqueConstraints( joinTableAnn.uniqueConstraints() );
+ JoinTable assocTable = property.getAnnotation( JoinTable.class );
+ CollectionTable collectionTable = property.getAnnotation( CollectionTable.class );
- //set check constaint in the second pass
+ if ( assocTable != null || collectionTable != null ) {
- JoinColumn[] joins = joinTableAnn.joinColumns();
+ final String catalog;
+ final String schema;
+ final String tableName;
+ final UniqueConstraint[] uniqueConstraints;
+ final JoinColumn[] joins;
+ final JoinColumn[] inverseJoins;
- if ( joins.length == 0 ) {
- annJoins = null;
+ //JPA 2 has priority
+ if (collectionTable != null) {
+ catalog = collectionTable.catalog();
+ schema = collectionTable.schema();
+ tableName = collectionTable.name();
+ uniqueConstraints = collectionTable.uniqueConstraints();
+ joins = collectionTable.joinColumns();
+ inverseJoins = null;
}
else {
- annJoins = joins;
+ catalog = assocTable.catalog();
+ schema = assocTable.schema();
+ tableName = assocTable.name();
+ uniqueConstraints = assocTable.uniqueConstraints();
+ joins = assocTable.joinColumns();
+ inverseJoins = assocTable.inverseJoinColumns();
}
- JoinColumn[] inverseJoins = joinTableAnn.inverseJoinColumns();
+ collectionBinder.setExplicitAssociationTable( true );
- if ( inverseJoins.length == 0 ) {
- annInverseJoins = null;
- }
- else {
- annInverseJoins = inverseJoins;
- }
+ if ( !BinderHelper.isDefault( schema ) ) associationTableBinder.setSchema( schema );
+ if ( !BinderHelper.isDefault( catalog ) ) associationTableBinder.setCatalog( catalog
);
+ if ( !BinderHelper.isDefault( tableName ) ) associationTableBinder.setName( tableName
);
+ associationTableBinder.setUniqueConstraints( uniqueConstraints );
+
+ //set check constaint in the second pass
+ annJoins = joins.length == 0 ? null : joins;
+ annInverseJoins = inverseJoins == null || inverseJoins.length == 0 ? null :
inverseJoins;
}
else {
annJoins = null;
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/array/Contest.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/array/Contest.java 2009-07-20
21:43:17 UTC (rev 17170)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/array/Contest.java 2009-07-20
23:24:38 UTC (rev 17171)
@@ -9,7 +9,6 @@
import javax.persistence.OneToMany;
import javax.persistence.ElementCollection;
-import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.IndexColumn;
/**
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/Screen.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/Screen.java 2009-07-20
21:43:17 UTC (rev 17170)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/Screen.java 2009-07-20
23:24:38 UTC (rev 17171)
@@ -12,9 +12,6 @@
import javax.validation.constraints.NotNull;
import javax.validation.Valid;
-import org.hibernate.annotations.CollectionOfElements;
-import org.hibernate.annotations.Cascade;
-
/**
* @author Emmanuel Bernard
*/
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java 2009-07-20
21:43:17 UTC (rev 17170)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java 2009-07-20
23:24:38 UTC (rev 17171)
@@ -17,6 +17,7 @@
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ElementCollection;
+import javax.persistence.CollectionTable;
import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.IndexColumn;
@@ -77,7 +78,7 @@
}
@ElementCollection
- @JoinTable(name = "ScorePerNickName", joinColumns = @JoinColumn(name =
"BoyId"))
+ @CollectionTable(name = "ScorePerNickName", joinColumns = @JoinColumn(name =
"BoyId"))
@Column(name = "score", nullable = false)
public Map<String, Integer> getScorePerNickName() {
return scorePerNickName;
@@ -88,7 +89,7 @@
}
@ElementCollection
- @JoinTable(
+ @CollectionTable(
name = "BoyFavoriteNumbers",
joinColumns = @JoinColumn(name = "BoyId")
)