gpt4 book ai didi

spring - Joda 时间和 hibernate 4

转载 作者:行者123 更新时间:2023-12-04 13:06:02 26 4
gpt4 key购买 nike

我正在将 hibernate 4 与 joda 时间和 spring 数据 jpa 一起使用。 Spring数据提供注解

@CreadedOn
@LastModifiedOn

我正在尝试使用这两个注释。下面是我的 pojo 的快照
@Entity
@Table(name="restaurant")
@Audited
public class Restaurant {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;

private String restaurantName;

@CreatedDate
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
// @Type(type = "org.jadira.usertype.dateandtime.threetenbp.PersistentDateTime")
private DateTime createdOn;

@LastModifiedDate
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
// @Type(type = "org.jadira.usertype.dateandtime.threetenbp.PersistentDateTime")
private DateTime modifiedOn;
}

按照提供的说明 user types jodatime ,我用 @Type 注释了我的属性.但仍然没有运气。每次我使用 @Type注释并部署它我在我的服务器上出现错误

SEVERE: Error listenerStart



完整的堆栈跟踪如下
    Jan 15, 2014 11:40:00 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive G:\apache-tomcat-7.0.47\webapps\base-spr
ing-data-jpa.war
Jan 15, 2014 11:40:00 AM org.apache.catalina.loader.WebappClassLoader validateJa
rFile
INFO: validateJarFile(G:\apache-tomcat-7.0.47\webapps\base-spring-data-jpa\WEB-I
NF\lib\javax.servlet-api-3.1.0.jar) - jar not loaded. See Servlet Spec 2.3, sect
ion 9.7.2. Offending class: javax/servlet/Servlet.class
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further detail
s.
Jan 15, 2014 11:40:05 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
Jan 15, 2014 11:40:05 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.7.Final}
Jan 15, 2014 11:40:05 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jan 15, 2014 11:40:05 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jan 15, 2014 11:40:05 AM org.hibernate.ejb.Ejb3Configuration configure
INFO: HHH000204: Processing PersistenceUnitInfo [
name: default
...]
Jan 15, 2014 11:40:05 AM org.hibernate.service.jdbc.connections.internal.Connect
ionProviderInitiator instantiateExplicitConnectionProvider
INFO: HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.c
onnection.InjectedDataSourceConnectionProvider
Jan 15, 2014 11:40:06 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Jan 15, 2014 11:40:06 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Jan 15, 2014 11:40:06 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/base-spring-data-jpa] startup failed due to previous errors
Jan 15, 2014 11:40:06 AM org.apache.catalina.loader.WebappClassLoader clearRefer
encesJdbc
SEVERE: The web application [/base-spring-data-jpa] registered the JDBC driver [
com.mysql.jdbc.Driver] but failed to unregister it when the web application was
stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistere
d.
Jan 15, 2014 11:40:06 AM org.apache.catalina.loader.WebappClassLoader clearRefer
encesThreads
SEVERE: The web application [/base-spring-data-jpa] appears to have started a th
read named [Abandoned connection cleanup thread] but has failed to stop it. This
is very likely to create a memory leak.
Jan 15, 2014 11:40:06 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory G:\apache-tomcat-7.0.47\webapps\docs
Jan 15, 2014 11:40:06 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory G:\apache-tomcat-7.0.47\webapps\exampl
es
Jan 15, 2014 11:40:06 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory G:\apache-tomcat-7.0.47\webapps\host-m
anager
Jan 15, 2014 11:40:07 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory G:\apache-tomcat-7.0.47\webapps\manage
r
Jan 15, 2014 11:40:07 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory G:\apache-tomcat-7.0.47\webapps\ROOT
Jan 15, 2014 11:40:07 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Jan 15, 2014 11:40:07 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-apr-8009"]
Jan 15, 2014 11:40:07 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 6648 ms

从昨天开始,我试图让这两项工作,但无法做到。谁能告诉我如何解决这个问题。下面是我的 pom 依赖项和存储库
 <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.7.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.27</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.5.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
<version>4.2.7.Final</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
</dependency>


    <repository>
<id>spring-libs-snapshot</id>
<url>http://repo.spring.io/libs-snapshot</url>
</repository>

</repositories>

最佳答案

您不需要使用 @Type 注释。只需添加以下 jpa 属性:

entityManagerFactory.getJpaPropertyMap().put("jadira.usertype.autoRegisterUserTypes", "true");

另外我认为你已经错过了 jadira 依赖:
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>3.1.0.CR10</version>
</dependency>

关于spring - Joda 时间和 hibernate 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21130538/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com