Tôi đang viết ứng dụng bằng cách sử dụng cơ sở dữ liệu postgresql và khung công tác spring + hibernate.spring - hibernate 5 cấu hình đặt tên chiến lược
Tôi đã nâng cấp khung công tác mùa xuân từ phiên bản 4.1.5.RELEASE lên 4.2.0.RELEASE và nâng cấp khung ngủ đông từ 4.3.7.Final lên 5.0.0Phiên bản gốc.
Sau khi nâng cấp, tôi gặp sự cố với NamingStrategy. Trong cơ sở dữ liệu postgresql, các tên cột của bảng được viết bằng chữ thường được phân tách bằng dấu gạch dưới, trong lớp ứng dụng, các thuộc tính bean nằm trong thư mục camelcase.
Đây là hoạt động tập tin cấu hình mùa xuân cho phiên bản cũ:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:component-scan base-package="fms" />
<bean id="microFmsDataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="***" />
<property name="username" value="***" />
<property name="password" value="***" />
<property name="testOnBorrow" value="true" />
<property name="testOnReturn" value="true" />
<property name="testWhileIdle" value="true" />
<property name="validationQuery" value="select 1" />
<property name="initialSize" value="5" />
<property name="minIdle" value="10" />
<property name="maxIdle" value="100" />
<property name="maxActive" value="100" />
<property name="removeAbandoned" value="true" />
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="microFmsDataSource"/>
<property name="packagesToScan">
<list>
<value>fms</value>
</list>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
<entry key="hibernate.hbm2ddl.auto" value="validate" />
<entry key="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<entry key="hibernate.show_sql" value="true" />
<entry key="hibernate.format_sql" value="true" />
<entry key="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy" />
</map>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
Sau khi nâng cấp tôi đã thay đổi cấu hình NamingStrategy:
<entry key="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy" />
như thế này:
<entry key="hibernate.implicit_naming_strategy" value="***" />
và thử tất cả các biến thể của các tùy chọn được liệt kê trong hibernate javadoc: https://docs.jboss.org/hibernate/orm/5.0/javadocs/org/hibernate/cfg/AvailableSettings.html#IMPLICIT_NAMING_STRATEGY
nhưng không thành công.
Bạn có thể cho tôi biết thay thế của ImprovedNamingStrategy trong Hibernate 5 và cung cấp ví dụ cấu hình hoạt động không?
tôi đã sử dụng di sản-JPA và nó làm việc cho tôi. Bạn có thể thử ? –
Sharadr
Bản sao có thể có của [ImprovedNamingStrategy không còn hoạt động trong Hibernate 5] (http://stackoverflow.com/questions/32437202/improvednamingstrategy-no-longer-working-in-hibernate-5) – Rich