Hibernate 春季一期工厂的两个Namingstrategies

Hibernate 春季一期工厂的两个Namingstrategies,hibernate,spring,annotations,Hibernate,Spring,Annotations,我正在使用Hibernate3.5和Spring3.0.4 我有一些旧表和一些新表,它们需要不同的NamingStrategies。我在春天宣布一个有着纳明策略的会期工厂 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="energyDataSo

我正在使用Hibernate3.5和Spring3.0.4

我有一些旧表和一些新表,它们需要不同的NamingStrategies。我在春天宣布一个有着纳明策略的会期工厂

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="energyDataSource" />
<property name="hibernateProperties">
  <value>
      hibernate.show_sql=true
      hibernate.dialect=org.hibernate.dialect.MySQLDialect
  </value>
</property>
<property name="namingStrategy" ref="namingStrategy"/>
<property name="annotatedClasses">
  <list>
    <!-- user stuff -->
    <value>user.model.UserAccount</value>
 <!--  energy   -->
    <value>com.energy.domain.Selskapstype</value>
 </list>
</property>

hibernate.show_sql=true
hibernate.dialogue=org.hibernate.dialogue.mysqldialogue
user.model.UserAccount
com.energy.domain.Selskapstype


我希望namingstrategy为UserAccount启动,但不为Selskapstype启动。有办法做到这一点吗?使用注释还是xml

当然,只需编写自己的
NamingStrategy
实现,根据表名将其委托给其他几种策略之一,然后将该自定义策略插入您的
会话工厂中即可,只需编写自己的
NamingStrategy
实现,根据表名将其委托给其他几种策略之一,然后将该自定义策略插入到您的
会话工厂中
您可以使用两种不同的会话工厂吗?一张旧桌子,一张新桌子?这样,您可以为每个sessionfactory设置不同的命名策略

为每个sessionfactory拥有不同的dao类,并相应地注入


干杯

您可以使用两个不同的会话工厂吗?一张旧桌子,一张新桌子?这样,您可以为每个sessionfactory设置不同的命名策略

为每个sessionfactory拥有不同的dao类,并相应地注入


干杯

这就是我最后要做的。我在dataAccessContext.xml中创建了该文件,该文件在启动时使用contextConfigLocation加载。这包括一个SessionFactory

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
...
<property name="namingStrategy" ref="namingStrategy"/>
...
</bean>

...
...
在我的web.xml中,我包含了映射到的OpenSessionInViewFilter/*

<filter>
<filter-name>HibernateSessionRequestFilter</filter-name>    
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
    <param-name>sessionFactoryBeanName</param-name>
    <param-value>sessionFactory</param-value>
</init-param>

HibernateSessionRequestFilter
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
sessionFactoryBeanName
会话工厂

然后,另一个sessionFactory包含在dataAccessContextEnergy.xml中,该文件导入到我的spring config energy-config.xml中

Energy-config.xml还包括一个opensessioninviewfilterinterceptor

<mvc:interceptors>
 <bean class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
  <property name="sessionFactory" ref="sessionFactoryEnergy"/>
 </bean>

然后我有两个会议工厂和两个公开会议。。。我希望如此


这是一个好的方法吗?还是我会在地狱里燃烧?:-)

这就是我最后要做的。我在dataAccessContext.xml中创建了该文件,该文件在启动时使用contextConfigLocation加载。这包括一个SessionFactory

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
...
<property name="namingStrategy" ref="namingStrategy"/>
...
</bean>

...
...
在我的web.xml中,我包含了映射到的OpenSessionInViewFilter/*

<filter>
<filter-name>HibernateSessionRequestFilter</filter-name>    
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
    <param-name>sessionFactoryBeanName</param-name>
    <param-value>sessionFactory</param-value>
</init-param>

HibernateSessionRequestFilter
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
sessionFactoryBeanName
会话工厂

然后,另一个sessionFactory包含在dataAccessContextEnergy.xml中,该文件导入到我的spring config energy-config.xml中

Energy-config.xml还包括一个opensessioninviewfilterinterceptor

<mvc:interceptors>
 <bean class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
  <property name="sessionFactory" ref="sessionFactoryEnergy"/>
 </bean>

然后我有两个会议工厂和两个公开会议。。。我希望如此


这是一个好的方法吗?还是我会在地狱里燃烧?:-)

哇-快速回答!我已经尝试制定我自己的NamingStrategy来覆盖@Override public String tableName(String tableName){return tableName;},这很有效。。但是我需要对columnname做同样的处理。这是很多专栏。所以我在寻找一个更容易的出路。(很抱歉这条评论的格式)哇-快速回答!我已经尝试制定我自己的NamingStrategy来覆盖@Override public String tableName(String tableName){return tableName;},这很有效。。但是我需要对columnname做同样的处理。这是很多专栏。所以我在寻找一个更容易的出路。(很抱歉这条评论的格式)是的,我可以。但是一个请求就有两个会话工厂。我必须检查用户是否使用一个sessionFactory登录,并使用另一个sessionFactory提供能量数据。使用OpenSessionInViewFilter,我担心它会变得一团糟。是的,我可以。但是一个请求就有两个会话工厂。我必须检查用户是否使用一个sessionFactory登录,并使用另一个sessionFactory提供能量数据。使用OpenSessionInViewFilter,我担心它会变得一团糟。