[hibernate-commits] Hibernate SVN: r10877 - in branches/Branch_3_2/HibernateExt/metadata/src: java/org/hibernate/cfg/annotations test/org/hibernate/test/annotations test/org/hibernate/test/annotations/quote

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Nov 29 09:24:40 EST 2006


Author: epbernard
Date: 2006-11-29 09:24:38 -0500 (Wed, 29 Nov 2006)
New Revision: 10877

Added:
   branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/quote/
   branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/quote/QuoteTest.java
   branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/quote/Role.java
   branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/quote/User.java
Modified:
   branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/TableBinder.java
Log:
ANN-476  Remove quotes when passing the values to the naming strategy

Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/TableBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/TableBinder.java	2006-11-29 14:19:45 UTC (rev 10876)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/TableBinder.java	2006-11-29 14:24:38 UTC (rev 10877)
@@ -43,8 +43,8 @@
 	String constraints;
 	Table denormalizedSuperTable;
 	ExtendedMappings mappings;
-	private String ownerEntityTable;
-	private String associatedEntityTable;
+	private Table ownerEntityTable;
+	private Table associatedEntityTable;
 	private String propertyName;
 	private String ownerEntity;
 	private String associatedEntity;
@@ -89,12 +89,20 @@
 	public Table bind() {
 		//logicalName only accurate for assoc table...
 		String logicalName = mappings.getNamingStrategy()
-				.logicalCollectionTableName( name, ownerEntityTable, associatedEntityTable, propertyName );
+				.logicalCollectionTableName(
+						name,
+						ownerEntityTable == null ? null : ownerEntityTable.getName(), //we remove potential quotes
+						associatedEntityTable == null ? null : associatedEntityTable.getName(), //we remove potential quotes
+						propertyName );
 		String extendedName = name != null ?
 				mappings.getNamingStrategy().tableName( name ) :
 				mappings.getNamingStrategy()
 						.collectionTableName(
-								ownerEntity, ownerEntityTable, associatedEntity, associatedEntityTable, propertyName
+								ownerEntity,
+								ownerEntityTable == null ? null : ownerEntityTable.getName(), //we remove potential quotes
+								associatedEntity,
+								associatedEntityTable == null ? null : associatedEntityTable.getName(), //we remove potential quotes 
+								propertyName
 						);
 		return fillTable(
 				schema, catalog,
@@ -359,9 +367,9 @@
 			String propertyName
 	) {
 		this.ownerEntity = ownerEntity;
-		this.ownerEntityTable = ownerEntityTable;
+		this.ownerEntityTable = ownerEntityTable != null ? new Table(ownerEntityTable) : null;
 		this.associatedEntity = associatedEntity;
-		this.associatedEntityTable = associatedEntityTable;
+		this.associatedEntityTable = associatedEntityTable != null ? new Table(associatedEntityTable) : null;
 		this.propertyName = propertyName;
 		this.name = null;
 	}

Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/quote/QuoteTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/quote/QuoteTest.java	2006-11-29 14:19:45 UTC (rev 10876)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/quote/QuoteTest.java	2006-11-29 14:24:38 UTC (rev 10877)
@@ -0,0 +1,35 @@
+//$Id: $
+package org.hibernate.test.annotations.quote;
+
+import org.hibernate.test.annotations.TestCase;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class QuoteTest extends TestCase {
+	public void testQuoteManytoMany() {
+		Session s = openSession();
+		Transaction tx = s.beginTransaction();
+		User u = new User();
+		s.persist( u );
+		Role r = new Role();
+		s.persist( r );
+		u.getRoles().add( r );
+		s.flush();
+		s.clear();
+		u = (User) s.get( User.class, u.getId() );
+		assertEquals( 1, u.getRoles().size() );
+		tx.rollback();
+		String role = User.class.getName() + ".roles";
+		assertEquals( "User_Role", getCfg().getCollectionMapping( role ).getCollectionTable().getName() );
+		s.close();
+	}
+	protected Class[] getMappings() {
+		return new Class[] {
+				User.class,
+				Role.class
+		};
+	}
+}

Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/quote/Role.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/quote/Role.java	2006-11-29 14:19:45 UTC (rev 10876)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/quote/Role.java	2006-11-29 14:24:38 UTC (rev 10877)
@@ -0,0 +1,22 @@
+//$Id: $
+package org.hibernate.test.annotations.quote;
+
+import java.io.Serializable;
+import javax.persistence.Id;
+import javax.persistence.Entity;
+import javax.persistence.GenerationType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Table;
+
+/**
+ * @author Emmanuel Bernard
+ */
+ at Entity
+ at Table(name = "`Role`")
+public class Role implements Serializable {
+
+   @Id
+   @GeneratedValue(strategy = GenerationType.AUTO)
+   private long id;
+
+}
\ No newline at end of file

Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/quote/User.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/quote/User.java	2006-11-29 14:19:45 UTC (rev 10876)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/quote/User.java	2006-11-29 14:24:38 UTC (rev 10877)
@@ -0,0 +1,44 @@
+//$Id: $
+package org.hibernate.test.annotations.quote;
+
+import java.io.Serializable;
+import java.util.Set;
+import java.util.HashSet;
+import javax.persistence.ManyToMany;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Table;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+/**
+ * @author Emmanuel Bernard
+ */
+ at Entity
+ at Table(name = "`User`")
+public class User implements Serializable {
+
+   @Id
+   @GeneratedValue(strategy = GenerationType.AUTO)
+   private long id;
+
+   @ManyToMany
+   private Set<Role> roles = new HashSet<Role>();
+
+
+	public long getId() {
+		return id;
+	}
+
+	public void setId(long id) {
+		this.id = id;
+	}
+
+	public Set<Role> getRoles() {
+		return roles;
+	}
+
+	public void setRoles(Set<Role> roles) {
+		this.roles = roles;
+	}
+}




More information about the hibernate-commits mailing list