import org.hibernate.cfg.improvednamingstrategy;@suppresswarnings("serial")public class nightnamingstrategy extends improvednamingstrategy{ private string tableprefix = "t_"; private string columnprefix = "c_"; @override public string collectiontablename(string ownerentity, string ownerentitytable, string associatedentity, string associatedentitytable, string propertyname) { return tablename(ownerentitytable + "_" + associatedentitytable); } @override public string propertytocolumnname(string propertyname) { return (this.columnprefix + super.propertytocolumnname(propertyname)).touppercase(); } @override public string classtotablename(string classname) { return (this.tableprefix + super.classtotablename(classname)).touppercase(); }}
<bean id="sessionfactory" class="org.springframework.orm.hibernate3.annotation.annotationsessionfactorybean"> <property name="datasource" ref="datasource" /> <!--配置命名规则--> <property name="namingstrategy"> <bean class="naming.nightnamingstrategy"></bean> </property> <property name="hibernateproperties"> <props> <prop key="hibernate.hbm2ddl.auto">${hbm2ddl.auto}</prop> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${show_sql}</prop> <prop key="hibernate.format_sql">${format_sql}</prop> <!--<prop key="hibernate.current_session_context_class">thread</prop>--> </props> </property> <property name="packagestoscan" value="tpcframework" /> </bean>