HHH-4077 add test for naming strategy in hbm files
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19225 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
bd9e6b1969
commit
84477a7816
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping
|
||||
package="org.hibernate.test.namingstrategy">
|
||||
<class name="Customers">
|
||||
<id name="id" column="id" type="int"/>
|
||||
<property name="specified_column" column="specified_column"/>
|
||||
</class>
|
||||
</hibernate-mapping>
|
|
@ -0,0 +1,25 @@
|
|||
package org.hibernate.test.namingstrategy;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class Customers implements java.io.Serializable {
|
||||
private int id;
|
||||
private String specified_column;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getSpecified_column() {
|
||||
return specified_column;
|
||||
}
|
||||
|
||||
public void setSpecified_column(String specified_column) {
|
||||
this.specified_column = specified_column;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package org.hibernate.test.namingstrategy;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.junit.functional.FunctionalTestCase;
|
||||
import org.hibernate.mapping.Column;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class NamingStrategyTest extends FunctionalTestCase {
|
||||
public void testCorrectDatabase() {
|
||||
PersistentClass classMapping = getCfg().getClassMapping( Customers.class.getName() );
|
||||
Column stateColumn = (Column) classMapping.getProperty( "specified_column" ).getColumnIterator().next();
|
||||
assertEquals( "CN_specified_column", stateColumn.getName() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
cfg.setNamingStrategy( new TestNamingStrategy() );
|
||||
}
|
||||
|
||||
public NamingStrategyTest(String string) {
|
||||
super( string );
|
||||
}
|
||||
|
||||
public String[] getMappings() {
|
||||
return new String[] {
|
||||
"namingstrategy/Customers.hbm.xml"
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package org.hibernate.test.namingstrategy;
|
||||
|
||||
import org.hibernate.cfg.DefaultNamingStrategy;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class TestNamingStrategy extends DefaultNamingStrategy {
|
||||
public String propertyToColumnName(String propertyName) {
|
||||
return "PTCN_" + propertyName;
|
||||
}
|
||||
|
||||
public String columnName(String columnName) {
|
||||
return "CN_" + columnName;
|
||||
}
|
||||
|
||||
public String logicalColumnName(String columnName, String
|
||||
propertyName) {
|
||||
return "LCN_" + super.logicalColumnName( columnName, propertyName );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue