我正在学习如何在春季项目中使用hibernate integration
,并尝试遵循以下示例:https://www.journaldev.com/3524/spring-hibernate-integration-example-tutorial
该教程具有pom.xml
和其他示例文件,但是我使用start.spring.io
初始化程序创建了一个pom.xml
文件,并尝试将自己的路径与该教程的示例集成。
因此,当我开始创建context.xml
并创建bean
时,如本教程所示,idea
在库中找不到任何类:
<bean id = "hibernate3AnnotatedSessionFactory"
class = "org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name = "dataSource" ref = "dataSource" />
因此,hibernate3
软件包对我不可用,我将软件包hibernate3
更改为hibernate5
,但是在这种情况下,annotation
软件包不可用,并且AnnotationSessionFactoryBean
类不可用。
问题
我可以在hibernate 5.v中使用“ AnnotationSessionFactoryBean”,还是已经过时的此类?
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<hibernate-version>5.3.7.Final</hibernate-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate-version}</version>
</dependency>
<!-- for JPA, use hibernate-entitymanager instead of hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate-version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
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">
<bean id="hibernate5AnnotatedSessionFactory"
class="org.springframework.orm.hibernate5.... - AnnotatedSessionFactory not avaiilable
答案 0 :(得分:1)
我认为您可以使用org.springframework.orm.hibernate5.LocalSessionFactoryBean
及其annotatedClasses
,annotatedPackages
或packagesToScan
属性。