Tôi đang cố gắng sử dụng Hibernate 5 (5.2.11) cùng với Spring ORM.org.hibernate.UnknownEntityTypeException: Không thể định vị persister: entity.Settings
hướng dẫn sau tôi đã đưa ra cấu hình sau:
Xuân Bean
<bean id="sessionFactorySettings" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
<prop key="hibernate.connection.driver_class">org.h2.Driver</prop>
<prop key="hibernate.connection.url">jdbc:h2:~/.dummy/settings</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>/hibernate.cfg.xml</value>
</list>
</property>
</bean>
Hibernate (hibernate.cfg.xml)
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<mapping class="entity.Settings"/>
</session-factory>
</hibernate-configuration>
Cấu hình này dẫn đến một org.hibernate.UnknownEntityTypeException: Unable to locate persister: entity.Settings
.
Tuy nhiên, ngay sau khi tôi di chuyển tất cả
<prop key="hibernate.xxx">..</prob>
tính vào hibernate.cfg.xml và tôi thay đổi cấu hình Spring để
<bean id="sessionFactorySettings" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="configLocation" value="/hibernate.cfg.xml"/>
</bean>
tất cả mọi thứ hoạt động tốt.
Bất kỳ ý tưởng nào tôi làm sai?
PS: Dependencies:
dependencies {
compile 'ch.qos.logback:logback-classic:1.2.3'
compile 'org.springframework:spring-context:4.3.11.RELEASE'
compile 'org.springframework:spring-jdbc:4.3.11.RELEASE'
compile 'org.springframework:spring-orm:4.3.11.RELEASE'
compile 'org.hibernate:hibernate-core:5.2.11.Final'
compile 'org.hibernate:hibernate-java8:5.2.11.Final'
compile 'org.apache.commons:commons-dbcp2:2.1.1'
compile 'com.h2database:h2:1.4.196'
}
Tôi chưa bao giờ thấy cấu hình bạn đã viết. Tôi luôn luôn sử dụng hoặc các tập tin cfg ngủ đông hoặc cấu hình hibernate mùa xuân. Bạn đã thử đặt danh sách lớp thực thể bên trong cấu hình mùa xuân chưa? –
Tôi cũng nghĩ rằng lớp thực thể nên ở bên trong cấu hình mùa xuân. Nhưng bằng cách nào? – Hannes