我正在学习如何在spring项目中使用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’,还是这个类已经过时了?
pom.xml:
<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>context.xml:
<?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
发布于 2018-11-15 11:00:39
我认为您可以使用org.springframework.orm.hibernate5.LocalSessionFactoryBean及其‘annotatedClasses、annotatedPackages或packagesToScan属性。
https://stackoverflow.com/questions/53211228
复制相似问题