3
回答
参考springside的jpa配置,感觉hibernate.ejb.naming_strategy没起作用啊

applicationContext.xml配置:


<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
<property name="packagesToScan" value="org.yye.testJpa"/>
<property name="jpaProperties">
<props>
<!-- 命名规则 My_NAME->MyName -->
<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
</props>
</property>
</bean>
实际使用时还是报 Unknown column,生成的sql中并没有按驼峰法反向转换过来:



select user0_.userId as userId1_0_, user0_.created as created2_0_, user0_.email as email3_0_, user0_.loginName as loginNam4_0_, user0_.loginPwd as loginPwd5_0_, user0_.name as name6_0_, user0_.phone as phone7_0_, user0_.roleId as roleId8_0_, user0_.sex as sex9_0_, user0_.status as status10_0_ from tb_user user0_ where user0_.loginName=?



求大神帮忙啊


举报
共有3个答案 最后回答: 1年前
我试了下,没问题呀,用的是hibernate 4.3.10
<bean name="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="packagesToScan">
            <list>
                <value>org.xxx.model</value>
            </list>
        </property>
        <property name="jpaDialect" ref="jpaDialect"/>
        <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
        <property name="jpaProperties">
            <map>
                <entry key="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
                <entry key="hibernate.show_sql" value="true"/>
                <entry key="hibernate.format_sql" value="false"/>
                <entry key="hibernate.hbm2ddl.auto" value="update"/>             
                <entry key="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
            </map>
        </property>
</bean>

生成的SQL:

Hibernate: select employee0_.id as id1_1_0_, employee0_.employee_address as employee2_1_0_, employee0_.employee_age as employee3_1_0_, employee0_.employee_birthday as employee4_1_0_, employee0_.employee_name as employee5_1_0_ from employee employee0_ where employee0_.id=?

谢谢回答,找到问题了,手贱下了最新版的hibernate 5:

NamingStrategy 被移除了,使用经过优化设计后的新 API:org.hibernate.boot.model.naming.ImplicitNamingStrategy和org.hibernate.boot.model.naming.PhysicalNamingStrategy

--- 共有 1 条评论 ---
菇凉windy请问具体是怎么使用呢 1年前 回复
顶部