HHH-4753 Default table name for @CollectionTable is not inferred correctly according to spec requirement

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18405 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Scott Marlow 2010-01-05 03:16:05 +00:00
parent 0987b4c06e
commit 39b098aac3
3 changed files with 148 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
@ -35,6 +39,35 @@ public class NamingStrategyTest extends TestCase {
}
}
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();