I am using hibernate 4 with joda time and spring data jpa. Spring data provides annotations
@CreadedOn
@LastModifiedOn
i am trying to use these two annotations.Below is a snapshot of my 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;
}
as per the instructions provided user types jodatime,i have annotated my properties with @Type
.but still no luck.Everytime i use the @Type
annotation and deploy it i get a error on my server
SEVERE: Error listenerStart
Full stack trace is below
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
Since yesterday i am trying to get these two work but unable to do so.Can anyone please tell me how to solve this problem.Below is my pom Dependencies and repository
<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>
You don't need to use @Type annotation. Just add following jpa property:
entityManagerFactory.getJpaPropertyMap().put("jadira.usertype.autoRegisterUserTypes", "true");
Also I think that you've missed jadira dependecy:
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>3.1.0.CR10</version>
</dependency>
If you use gradle and spring boot with annotation based configuration you can use @jakub-kubrynski advice by
build.gradle
dependencies {
compile 'org.jadira.usertype:usertype.core:3.2.0.GA'
}
application.properties
#Hibernate config
spring.jpa.properties.jadira.usertype.autoRegisterUserTypes=true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With