这段时间因为数据量的增大,数据库进行分表设计,分表格式和原来一样只是表明后面添加了年月,例如:tableName1011。
现在要在原有ssh框架下进行添加此功能。
经过网上搜相关资料,又碰到javaeye的被封,搞得我身心疲惫啊!
现在的状态还没成功,我给大伙报告一下情况,请各位指导一下。
codes:
我自己的类继承了DefaultNamingStrategy来修改hibernate的映射表明。
public class DBNameStrategy extends DefaultNamingStrategy {
/**
* 覆盖了 classToTableName方法
*/
private static final long serialVersionUID = 8154575377606674593L;
public java.lang.String classToTableName(java.lang.String className) {
String name;
SimpleDateFormat sdf = new SimpleDateFormat("yyMM");
String date = sdf.format(new Date());
if (className.equalsIgnoreCase("JfglJfwtxx")) {
name = "JFGL_JFWTXX" + date;
} else if (className.equalsIgnoreCase("JfglJfhbxx")) {
name = "JFGL_JFHBXX" + date;
} else if (className.equalsIgnoreCase("MdglMdbzjls")) {
name = "MDGL_MDBZJLS" + date;
} else if (className.equalsIgnoreCase("ZhglZhywls")) {
name = "ZHGL_ZHYWLS" + date;
} else {
name = className;
}
return name;
}
}
然后在application.xml配置文件配置了sessionFactory的属性
codes:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="mappingDirectoryLocations">
<list>
<value>${hibernate.mapping.dir}</value>
</list>
</property>
<property name="schemaUpdate">
<value>${hibernate.schemaUpdate}</value>
</property>
<property name="lobHandler">
<ref local="lobHandler" />
</property>
<property name="namingStrategy">
<bean class="com.neili.namingStrategy.DBNameStrategy" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<prop key="hibernate.show_sql">
${hibernate.show_sql}
</prop>
<!-- 查询缓存,CACHE缓存 -->
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<!-- END -->
<prop key="hibernate.cglib.use_reflection_optimizer">
${hibernate.cglib.use_reflection_optimizer}
</prop>
<prop key="hibernate.connection.provider_class">
${hibernate.connection.provider_class}
</prop>
<prop key="hibernate.proxool.properties">
${hibernate.proxool.properties}
</prop>
<prop key="hibernate.proxool.pool_alias">
${hibernate.proxool.pool_alias}
</prop>
</props>
</property>
</bean>
现在项目启动没问题,可是对相应表进行更新还不是更新的对应的表。
请各位看看,我会持续更新的,一定会解决这个问题。