I'm trying to get a NamingStrategy working, because with have to Prefix our tables with the project name, for Example: TEST_TableName
Now I've tried to configure this(Not really Documented), but it is being ignored so far:
Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass"> <value>com.ibm.db2.jcc.DB2Driver</value> </property> <property name="jdbcUrl"> <value>jdbc:db2://localhost:50000/TEST </value> </property> <property name="user"> <value>***</value> </property> <property name="password"> <value>***</value> </property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="namingStrategy" ref="MyNamingStrategy" /> <property name="dataSource" ref="dataSource" /> <property name="packagesToScan"> <list> <value>ch.test.MyWebShop.domain.* </value> </list> </property> <property name="hibernateProperties"> <value> hibernate.c3p0.min_size=5 hibernate.c3p0.max_size=20 hibernate.c3p0.timeout=1800 hibernate.c3p0.max_statements=50 hibernate.dialect=org.hibernate.dialect.DB2Dialect hibernate.show_sql=true hibernate.format_sql=true hibernate.hbm2ddl.auto=create hibernate.id.new_generator_mappings=true </value> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="MyNamingStrategy" class="ch.test.MyWebShop.hibernate.MyNamingStrategy" /> <tx:annotation-driven transaction-manager="transactionManager" /> </beans>
Tried to if something happens:
Nothing happend, nowhere has FRT shown up, not on the Database nor in the logging Output. Bean MyNamingStrategy is being initialized and Property namingStrategy is recognized.Code:package ch.test.MyWebShop.hibernate; import org.hibernate.cfg.ImprovedNamingStrategy; @SuppressWarnings("serial") public class MyNamingStrategy extends ImprovedNamingStrategy { @Override public String collectionTableName(String ownerEntity, String ownerEntityTable, String associatedEntity, String associatedEntityTable, String propertyName) { // TODO Auto-generated method stub return "FRT_" + super.collectionTableName(ownerEntity, ownerEntityTable, associatedEntity, associatedEntityTable, propertyName); } @Override public String columnName(String columnName) { // TODO Auto-generated method stub return "FRT_" + super.columnName(columnName); } @Override public String foreignKeyColumnName(String propertyName, String propertyEntityName, String propertyTableName, String referencedColumnName) { // TODO Auto-generated method stub return"FRT_" + super.foreignKeyColumnName(propertyName, propertyEntityName, propertyTableName, referencedColumnName); } @Override public String joinKeyColumnName(String joinedColumn, String joinedTable) { // TODO Auto-generated method stub return"FRT_" + super.joinKeyColumnName(joinedColumn, joinedTable); } @Override public String logicalCollectionColumnName(String columnName, String propertyName, String referencedColumn) { // TODO Auto-generated method stub return"FRT_" + super.logicalCollectionColumnName(columnName, propertyName, referencedColumn); } @Override public String logicalCollectionTableName(String tableName, String ownerEntityTable, String associatedEntityTable, String propertyName) { // TODO Auto-generated method stub return "FRT_" + super.logicalCollectionTableName(tableName, ownerEntityTable, associatedEntityTable, propertyName); } @Override public String logicalColumnName(String columnName, String propertyName) { // TODO Auto-generated method stub return"FRT_" + super.logicalColumnName(columnName, propertyName); } @Override public String propertyToColumnName(String propertyName) { // TODO Auto-generated method stub return"FRT_" + super.propertyToColumnName(propertyName); } @Override public String tableName(String tableName) { // TODO Auto-generated method stub return "FRT_" + super.tableName(tableName); } @Override public String classToTableName(String arg0) { return "FRT_" + super.classToTableName(arg0); } }


Reply With Quote