HHH-4855 globally quoting identifiers was incorrectly considered an actual table name

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18653 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Emmanuel Bernard 2010-01-27 17:22:13 +00:00
parent 62e4d6e227
commit 3e766c1397
7 changed files with 192 additions and 2 deletions

View File

@ -352,8 +352,13 @@ public class Ejb3Column {
}
public void setSecondaryTableName(String secondaryTableName) {
if ( "``".equals( secondaryTableName ) ) {
this.secondaryTableName = "";
}
else {
this.secondaryTableName = secondaryTableName;
}
}
public static Ejb3Column[] buildColumnFromAnnotation(
javax.persistence.Column[] anns,

View File

@ -0,0 +1,52 @@
package org.hibernate.test.annotations.quote;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityResult;
import javax.persistence.Id;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.Table;
/**
* @author Emmanuel Bernard
*/
@Entity
@Table(name = "PHONE")
public class Phone implements java.io.Serializable {
private Integer id;
private String brandName;
private float price;
public Phone() {
}
@Id
@Column(name="ID")
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name="BRANDNAME")
public String getBrandName() {
return brandName;
}
public void setBrandName(String bName) {
this.brandName = bName;
}
@Column(name="PRICE")
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
}

View File

@ -0,0 +1,45 @@
package org.hibernate.test.annotations.quote;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.test.annotations.TestCase;
/**
* @author Emmanuel Bernard
*/
public class QuoteGlobalTest 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();
}
@Override
protected void configure(Configuration cfg) {
super.configure( cfg );
cfg.setProperty( Environment.GLOBALLY_QUOTED_IDENTIFIERS, "true" );
}
protected Class[] getAnnotatedClasses() {
return new Class[] {
User.class,
Role.class,
Phone.class
};
}
}

View File

@ -29,7 +29,8 @@ public class QuoteTest extends TestCase {
protected Class[] getAnnotatedClasses() {
return new Class[] {
User.class,
Role.class
Role.class,
Phone.class
};
}
}

View File

@ -0,0 +1,52 @@
package org.hibernate.ejb.test.mapping;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityResult;
import javax.persistence.Id;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.Table;
/**
* @author Emmanuel Bernard
*/
@Entity
@Table(name = "PHONE")
public class Phone implements java.io.Serializable {
private Integer id;
private String brandName;
private float price;
public Phone() {
}
@Id
@Column(name="ID")
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name="BRANDNAME")
public String getBrandName() {
return brandName;
}
public void setBrandName(String bName) {
this.brandName = bName;
}
@Column(name="PRICE")
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
}

View File

@ -0,0 +1,27 @@
package org.hibernate.ejb.test.mapping;
import org.hibernate.ejb.test.TestCase;
/**
* @author Emmanuel Bernard
*/
public class QuotingTest extends TestCase {
public void testQuote() {
// the configuration was failing
}
@Override
public String[] getEjb3DD() {
return new String[] {
"org/hibernate/ejb/test/mapping/orm.xml"
};
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Phone.class
};
}
}

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" version="2.0">
<persistence-unit-metadata>
<persistence-unit-defaults>
<delimited-identifiers/>
</persistence-unit-defaults>
</persistence-unit-metadata>
</entity-mappings>