Author: epbernard
Date: 2007-08-09 12:20:27 -0400 (Thu, 09 Aug 2007)
New Revision: 12910
Modified:
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationBinder.java
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/SecondaryTableSecondPass.java
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/EntityBinder.java
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/join/JoinTest.java
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/manytomany/Cat.java
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/query/Chaos.java
Log:
ANN-648 handle joins table when dealing with comments and indexes
Modified: trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
---
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationBinder.java 2007-08-09
15:01:14 UTC (rev 12909)
+++
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationBinder.java 2007-08-09
16:20:27 UTC (rev 12910)
@@ -773,8 +773,8 @@
mappings.addClass( persistentClass );
- mappings.addSecondPass( new SecondaryTableSecondPass( entityBinder, propertyHolder )
);
- //entityBinder.finalSecondaryTableBinding( propertyHolder );
+ //Process secondary tables and complementary definitions (ie o.h.a.Table)
+ mappings.addSecondPass( new SecondaryTableSecondPass( entityBinder, propertyHolder,
annotatedClass ) );
//add process complementary Table definition (index & all)
entityBinder.processComplementaryTableDefinitions( annotatedClass.getAnnotation(
org.hibernate.annotations.Table.class ) );
Modified:
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/SecondaryTableSecondPass.java
===================================================================
---
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/SecondaryTableSecondPass.java 2007-08-09
15:01:14 UTC (rev 12909)
+++
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/SecondaryTableSecondPass.java 2007-08-09
16:20:27 UTC (rev 12910)
@@ -4,6 +4,7 @@
import java.util.Map;
import org.hibernate.MappingException;
+import org.hibernate.annotations.common.reflection.XAnnotatedElement;
import org.hibernate.cfg.annotations.EntityBinder;
/**
@@ -12,13 +13,16 @@
public class SecondaryTableSecondPass implements SecondPass {
private EntityBinder entityBinder;
private PropertyHolder propertyHolder;
+ private XAnnotatedElement annotatedClass;
- public SecondaryTableSecondPass(EntityBinder entityBinder, PropertyHolder
propertyHolder) {
+ public SecondaryTableSecondPass(EntityBinder entityBinder, PropertyHolder
propertyHolder, XAnnotatedElement annotatedClass) {
this.entityBinder = entityBinder;
this.propertyHolder = propertyHolder;
+ this.annotatedClass = annotatedClass;
}
public void doSecondPass(Map persistentClasses) throws MappingException {
entityBinder.finalSecondaryTableBinding( propertyHolder );
+
}
}
Modified:
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/EntityBinder.java
===================================================================
---
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/EntityBinder.java 2007-08-09
15:01:14 UTC (rev 12909)
+++
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/EntityBinder.java 2007-08-09
16:20:27 UTC (rev 12910)
@@ -740,19 +740,30 @@
}
public void processComplementaryTableDefinitions(org.hibernate.annotations.Table table)
{
+ //comment and index are processed here
if ( table == null ) return;
String appliedTable = table.appliesTo();
Iterator tables = persistentClass.getTableClosureIterator();
Table hibTable = null;
while ( tables.hasNext() ) {
- hibTable = (Table) tables.next();
- if ( hibTable.getQuotedName().equals( appliedTable ) ) {
+ Table pcTable = (Table) tables.next();
+ if ( pcTable.getQuotedName().equals( appliedTable ) ) {
//we are in the correct table to find columns
+ hibTable = pcTable;
break;
}
hibTable = null;
}
if ( hibTable == null ) {
+ //maybe a join/secondary table
+ for ( Join join : secondaryTables.values() ) {
+ if ( join.getTable().getQuotedName().equals( appliedTable ) ) {
+ hibTable = join.getTable();
+ break;
+ }
+ }
+ }
+ if ( hibTable == null ) {
throw new AnnotationException(
"(a)org.hibernate.annotations.Table references an unknown table: " +
appliedTable
);
Modified:
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/join/JoinTest.java
===================================================================
---
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/join/JoinTest.java 2007-08-09
15:01:14 UTC (rev 12909)
+++
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/join/JoinTest.java 2007-08-09
16:20:27 UTC (rev 12910)
@@ -197,10 +197,10 @@
*/
protected Class[] getMappings() {
return new Class[]{
- //Life.class,
- //Death.class,
- //Cat.class,
- //Dog.class,
+ Life.class,
+ Death.class,
+ Cat.class,
+ Dog.class,
A.class,
B.class,
C.class
Modified:
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/manytomany/Cat.java
===================================================================
---
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/manytomany/Cat.java 2007-08-09
15:01:14 UTC (rev 12909)
+++
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/manytomany/Cat.java 2007-08-09
16:20:27 UTC (rev 12910)
@@ -6,18 +6,26 @@
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
+import javax.persistence.JoinTable;
+import javax.persistence.JoinColumn;
+import org.hibernate.annotations.Index;
+
/**
* @author Emmanuel Bernard
*/
@Entity
@Table(name = "tbl_cat")
+//ANN-630
+//(a)org.hibernate.annotations.Table(appliesTo= "TT", indexes = @Index(name =
"testidx", columnNames = "cat_id"))
public class Cat {
private CatPk id;
private int age;
private Set<Woman> humanContacts;
@ManyToMany
+ //@Index(name = "CAT_HUMAN_IDX")
+ @JoinTable(name="TT")
public Set<Woman> getHumanContacts() {
return humanContacts;
}
Modified:
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/query/Chaos.java
===================================================================
---
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/query/Chaos.java 2007-08-09
15:01:14 UTC (rev 12909)
+++
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/query/Chaos.java 2007-08-09
16:20:27 UTC (rev 12910)
@@ -10,6 +10,7 @@
import javax.persistence.NamedNativeQuery;
import javax.persistence.OneToMany;
import javax.persistence.JoinColumn;
+import javax.persistence.Column;
import org.hibernate.annotations.SQLInsert;
import org.hibernate.annotations.SQLUpdate;
@@ -22,17 +23,18 @@
*/
@Entity
@Table(name="CHAOS")
-@SQLInsert( sql="INSERT INTO CHAOS(name, nickname, size, id)
VALUES(upper(?),?,?,?)")
-@SQLUpdate( sql="UPDATE CHAOS SET name = upper(?), nickname = ?, size = ? WHERE id =
?")
+@SQLInsert( sql="INSERT INTO CHAOS(name, nick_name, size, id)
VALUES(upper(?),?,?,?)")
+@SQLUpdate( sql="UPDATE CHAOS SET name = upper(?), nick_name = ?, size = ? WHERE id
= ?")
@SQLDelete( sql="DELETE CHAOS WHERE id = ?")
@SQLDeleteAll( sql="DELETE CHAOS")
@Loader(namedQuery = "chaos")
-@NamedNativeQuery(name="chaos", query="select id, size, name, lower(
nickname ) as nickname from CHAOS where id= ?", resultClass = Chaos.class)
+@NamedNativeQuery(name="chaos", query="select id, size, name, lower(
nick_name ) as nick_name from CHAOS where id= ?", resultClass = Chaos.class)
public class Chaos {
@Id
private Long id;
private Long size;
private String name;
+ @Column(name="nick_name")
private String nickname;
@OneToMany