Author: smarlow(a)redhat.com
Date: 2010-01-04 22:16:05 -0500 (Mon, 04 Jan 2010)
New Revision: 18405
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/namingstrategy/A.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/namingstrategy/AddressEntry.java
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/namingstrategy/NamingStrategyTest.java
Log:
HHH-4753 Default table name for @CollectionTable is not inferred correctly according to
spec requirement
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/namingstrategy/A.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/namingstrategy/A.java
(rev 0)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/namingstrategy/A.java 2010-01-05
03:16:05 UTC (rev 18405)
@@ -0,0 +1,68 @@
+package org.hibernate.test.annotations.namingstrategy;
+
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Id;
+import javax.persistence.ElementCollection;
+import javax.persistence.Column;
+import javax.persistence.JoinColumn;
+import javax.persistence.CascadeType;
+import javax.persistence.CollectionTable;
+
+@Entity
+@Table(name = "AEC")
+public class A implements java.io.Serializable {
+ @Id
+ protected String id;
+ protected String name;
+ protected int value;
+
+ @ElementCollection
+ protected Set<AddressEntry> address = new HashSet();
+
+ public A() {
+ }
+
+ public A(String id, String name, int value) {
+ this.id = id;
+ this.name = name;
+ this.value = value;
+ }
+
+ // Default to table A_AddressEntry
+ public Set<AddressEntry> getAddress() {
+ return address;
+ }
+
+ public void setAddress(Set<AddressEntry> addr) {
+ this.address = addr;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(int val) {
+ this.value = val;
+ }
+}
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/namingstrategy/AddressEntry.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/namingstrategy/AddressEntry.java
(rev 0)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/namingstrategy/AddressEntry.java 2010-01-05
03:16:05 UTC (rev 18405)
@@ -0,0 +1,45 @@
+package org.hibernate.test.annotations.namingstrategy;
+
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class AddressEntry implements java.io.Serializable {
+ protected String street;
+ protected String city;
+ protected String state;
+ protected String zip;
+
+ public AddressEntry() {
+ }
+
+ public AddressEntry( String street, String city, String state, String zip) {
+ this.street = street;
+ this.city = city;
+ this.state = state;
+ this.zip = zip;
+ }
+ public String getCity() {
+ return city;
+ }
+ public void setCity(String c) {
+ city = c;
+ }
+ public String getState() {
+ return state;
+ }
+ public void setState(String state) {
+ this.state = state;
+ }
+ public String getStreet() {
+ return street;
+ }
+ public void setStreet(String street) {
+ this.street = street;
+ }
+ public String getZip() {
+ return zip;
+ }
+ public void setZip(String zip) {
+ this.zip = zip;
+ }
+}
\ No newline at end of file
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/namingstrategy/NamingStrategyTest.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/namingstrategy/NamingStrategyTest.java 2010-01-04
20:14:42 UTC (rev 18404)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/namingstrategy/NamingStrategyTest.java 2010-01-05
03:16:05 UTC (rev 18405)
@@ -1,12 +1,16 @@
-// $Id:$
+// $Id$
package org.hibernate.test.annotations.namingstrategy;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.util.Iterator;
import junit.framework.TestCase;
import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.EJB3NamingStrategy;
+import org.hibernate.cfg.Mappings;
+import org.hibernate.mapping.Table;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,7 +38,36 @@
fail(e.getMessage());
}
}
-
+
+ public void testWithEJB3NamingStrategy() throws Exception {
+ try {
+ AnnotationConfiguration config = new AnnotationConfiguration();
+ config.setNamingStrategy(EJB3NamingStrategy.INSTANCE);
+ config.addAnnotatedClass(A.class);
+ config.addAnnotatedClass(AddressEntry.class);
+ config.buildSessionFactory();
+ Mappings mappings = config.createMappings();
+ boolean foundIt = false;
+
+ for ( Iterator iter = mappings.iterateTables(); iter.hasNext(); ) {
+ Table table = (Table) iter.next();
+ log.info("testWithEJB3NamingStrategy table = " + table.getName());
+ if ( table.getName().equalsIgnoreCase("A_ADDRESS")) {
+ foundIt = true;
+ }
+ // make sure we use A_ADDRESS instead of AEC_address
+ assertFalse("got table name mapped to: AEC_address which violates JPA-2 spec
section 11.1.8
([OWNING_ENTITY_NAME]_[COLLECTION_ATTRIBUTE_NAME])",table.getName().equalsIgnoreCase("AEC_address"));
+ }
+ assertTrue("table not mapped to A_ADDRESS which violates JPA-2 spec section
11.1.8",foundIt);
+ }
+ catch( Exception e ) {
+ StringWriter writer = new StringWriter();
+ e.printStackTrace(new PrintWriter(writer));
+ log.debug(writer.toString());
+ fail(e.getMessage());
+ }
+ }
+
public void testWithoutCustomNamingStrategy() throws Exception {
try {
AnnotationConfiguration config = new AnnotationConfiguration();