我想将Spring与Hibernate 5一起使用。但是在启动过程中,出现此错误:
Caused by: java.lang.ClassNotFoundException: Could not load requested class : datetime
这是我的POM.xml配置:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.0.7.RELEASE</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.10.RELEASE</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<version>1.5.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.3.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.3.6.Final</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.reactivestreams</groupId>
<artifactId>reactive-streams</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.1.Final</version>
</dependency>
完整的Java错误堆栈: https://pastebin.com/a01yU4vZ
我的模型中有想要在MariaDB中使用的日期时间。
@Type(type = "datetime")
@Temporal(TemporalType.DATE)
private DateType datetime;
我想我缺少Hibernate的一些POM依赖项。您能告诉我一些必须添加什么依赖性才能解决该问题吗?
编辑:
对于日期时间休眠配置,我使用:
@Column
@Type(type = "datetime")
@Temporal(TemporalType.DATE)
private DateType datetime;
答案 0 :(得分:0)
您拥有的休眠日期中没有日期时间类型:
Name = date Java Type = java.sql.Date
Name = calendar_date Java Type = java.util.Calendar
如果您使用的是Java 8
NAme = LocalDate Java Type = java.time.OffsetDateTime
Name = LocalDateTimeType Java Type = java.time.LocalDateTime
中查看更多内容
答案 1 :(得分:0)
对于您的实体字段datetime
,应使用:
@Column
@Temporal(TemporalType.DATE)
private java.util.Date datetime`
或java.time
包中的类之一。在后一种情况下,您可能还需要添加following dependency:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-java8</artifactId>
<version>5.3.2.Final</version>
</dependency>
在两种情况下,我都不认为注释@Type(type = "datetime")
是必需的。