java - Spring error: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL -
i learn spring , have problem:
org.springframework.beans.factory.beancreationexception: error creating bean name 'entitymanagerfactory' defined in url [file:/c:/users/pantau_acc/desktop/spring/target/classes/applicationcontext.xml]: invocation of init method failed; nested exception javax.persistence.persistenceexception: [persistenceunit: com.donutek] unable build hibernate sessionfactory @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1578) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:545) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:482) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:306) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:302) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:197) @ org.springframework.context.support.abstractapplicationcontext.getbean(abstractapplicationcontext.java:1054) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:829) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:538) @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:446) @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:328) @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:107) @ org.eclipse.jetty.server.handler.contexthandler.callcontextinitialized(contexthandler.java:800) @ org.eclipse.jetty.servlet.servletcontexthandler.callcontextinitialized(servletcontexthandler.java:444) @ org.eclipse.jetty.server.handler.contexthandler.startcontext(contexthandler.java:791) @ org.eclipse.jetty.servlet.servletcontexthandler.startcontext(servletcontexthandler.java:294) @ org.eclipse.jetty.webapp.webappcontext.startwebapp(webappcontext.java:1349) @ org.eclipse.jetty.maven.plugin.jettywebappcontext.startwebapp(jettywebappcontext.java:296) @ org.eclipse.jetty.webapp.webappcontext.startcontext(webappcontext.java:1342) @ org.eclipse.jetty.server.handler.contexthandler.dostart(contexthandler.java:741) @ org.eclipse.jetty.webapp.webappcontext.dostart(webappcontext.java:505) @ org.eclipse.jetty.maven.plugin.jettywebappcontext.dostart(jettywebappcontext.java:365) @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:68) @ org.eclipse.jetty.util.component.containerlifecycle.start(containerlifecycle.java:132) @ org.eclipse.jetty.util.component.containerlifecycle.dostart(containerlifecycle.java:114) @ org.eclipse.jetty.server.handler.abstracthandler.dostart(abstracthandler.java:61) @ org.eclipse.jetty.server.handler.contexthandlercollection.dostart(contexthandlercollection.java:163) @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:68) @ org.eclipse.jetty.util.component.containerlifecycle.start(containerlifecycle.java:132) @ org.eclipse.jetty.util.component.containerlifecycle.dostart(containerlifecycle.java:114) @ org.eclipse.jetty.server.handler.abstracthandler.dostart(abstracthandler.java:61) @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:68) @ org.eclipse.jetty.util.component.containerlifecycle.start(containerlifecycle.java:132) @ org.eclipse.jetty.server.server.start(server.java:387) @ org.eclipse.jetty.util.component.containerlifecycle.dostart(containerlifecycle.java:114) @ org.eclipse.jetty.server.handler.abstracthandler.dostart(abstracthandler.java:61) @ org.eclipse.jetty.server.server.dostart(server.java:354) @ org.eclipse.jetty.maven.plugin.jettyserver.dostart(jettyserver.java:73) @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:68) @ org.eclipse.jetty.maven.plugin.abstractjettymojo.startjetty(abstractjettymojo.java:534) @ org.eclipse.jetty.maven.plugin.abstractjettymojo.execute(abstractjettymojo.java:357) @ org.eclipse.jetty.maven.plugin.jettyrunmojo.execute(jettyrunmojo.java:167) @ org.apache.maven.plugin.defaultbuildpluginmanager.executemojo(defaultbuildpluginmanager.java:101) @ org.apache.maven.lifecycle.internal.mojoexecutor.execute(mojoexecutor.java:209) @ org.apache.maven.lifecycle.internal.mojoexecutor.execute(mojoexecutor.java:153) @ org.apache.maven.lifecycle.internal.mojoexecutor.execute(mojoexecutor.java:145) @ org.apache.maven.lifecycle.internal.lifecyclemodulebuilder.buildproject(lifecyclemodulebuilder.java:84) @ org.apache.maven.lifecycle.internal.lifecyclemodulebuilder.buildproject(lifecyclemodulebuilder.java:59) @ org.apache.maven.lifecycle.internal.lifecyclestarter.singlethreadedbuild(lifecyclestarter.java:183) @ org.apache.maven.lifecycle.internal.lifecyclestarter.execute(lifecyclestarter.java:161) @ org.apache.maven.defaultmaven.doexecute(defaultmav en.java:320) @ org.apache.maven.defaultmaven.execute(defaultmaven.java:156) @ org.apache.maven.cli.mavencli.execute(mavencli.java:537) @ org.apache.maven.cli.mavencli.domain(mavencli.java:196) @ org.apache.maven.cli.mavencli.main(mavencli.java:141) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ org.codehaus.plexus.classworlds.launcher.launcher.launchenhanced(launcher.java:290) @ org.codehaus.plexus.classworlds.launcher.launcher.launch(launcher.java:230) @ org.codehaus.plexus.classworlds.launcher.launcher.mainwithexitcode(launcher.java:409) @ org.codehaus.plexus.classworlds.launcher.launcher.main(launcher.java:352) caused by: javax.persistence.persistenceexception: [persistenceunit: com.donutek] unable build hibernate sessionfactory
when run project entity loginlog
.
import java.io.serializable; import java.util.date; import javax.persistence.entity; import javax.persistence.table; @entity @table(name = "login_log") public class loginlog extends baseobject implements serializable { private date date; private string ip; private user user; public loginlog() { // } public loginlog(date date, string ip, user user) { this.date = date; this.ip = ip; this.user = user; } public date getdate() { return date; } public void setdate(date date) { this.date = date; } public string getip() { return ip; } public void setip(string ip) { this.ip = ip; } public user getuser() { return user; } public void setuser(user user) { this.user = user; } }
base object is:
@mappedsuperclass public class baseobject { private long id; /** * * @return true if entity hasn't been persisted yet */ @transient public boolean isnew() { return id == null; } @id @generatedvalue public long getid() { return id; } public void setid(long id) { this.id = id; } }
applicationcontext.xml
is:
<?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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation= "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd" > <context:annotation-config/> <context:component-scan base-package="com.donutek.**.*"/> <tx:annotation-driven transaction-manager="transactionmanager" /> <bean id="entitymanagerfactory" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean" destroy-method="destroy"> <property name="persistencexmllocation" value="classpath:/meta-inf/persistence.xml"/> <property name="jpavendoradapter" ref="hibernatevendoradapter"/> <property name="packagestoscan" value="com.donutek.**.domain"/> <property name="persistenceunitname" value="com.donutek"/> </bean> <bean id="hibernatevendoradapter" class="org.springframework.orm.jpa.vendor.hibernatejpavendoradapter"/> <!-- transaction manager single entitymanagerfactory (alternative jta) --> <bean id="transactionmanager" class="org.springframework.orm.jpa.jpatransactionmanager"> <property name="entitymanagerfactory" ref="entitymanagerfactory"/> </bean> </beans>
i think, problem in public loginlog(date date, string ip, user user)
, because when run code without user user
in loginlog
class, it's normaly working.
can me?
thank advice.
spring version is: 4.2.4.release
edit: user.java
is:
import java.util.date; import javax.persistence.column; import javax.persistence.entity; import javax.persistence.table; @entity @table(name = "user") public class user extends baseobject { /** * login, unique */ private string email; /** * secret signing-in */ private string password; /** * date of user registration */ private date dateregistration; /** * user nick name */ private string nickname; /** * state of user accoutn */ private userstate useraccstate; public user() { // } public user(string email, string password, string nickname) { this.email = email; this.password = password; this.dateregistration = new date(); this.nickname = nickname; this.useraccstate = userstate.acc_waitingforactivated; } @column(unique = true) public string getemail() { return email; } public void setemail(string email) { this.email = email; } public string getpassword() { return password; } public void setpassword(string password) { this.password = password; } public date getdateregistration() { return dateregistration; } public void setdateregistration(date dateregistration) { this.dateregistration = dateregistration; } public string getnickname() { return nickname; } public void setnickname(string nickname) { this.nickname = nickname; } public userstate getuseraccstate() { return useraccstate; } public void setuseraccstate(userstate useraccstate) { this.useraccstate = useraccstate; } }
persistence.xml
is:
<?xml version="1.0" encoding="utf-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0"> <persistence-unit name="com.donutek" transaction-type="resource_local"> <provider>org.hibernate.jpa.hibernatepersistenceprovider</provider> <properties> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="openjpa.jdbc.synchronizemappings" value="buildschema"/> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.driver"/> <property name="hibernate.connection.password" value=""/> <property name="hibernate.connection.username" value="root"/> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/spring"/> <property name="hibernate.dialect" value="org.hibernate.dialect.mysql5innodbdialect"/> <property name="hibernate.validator.apply_to_ddl" value="true" /> <property name="connection.provider_class" value="org.hibernate.connection.c3p0connectionprovider"/> <property name="hibernate.c3p0.min_size" value="5"/> <property name="hibernate.c3p0.max_size" value="20"/> <property name="hibernate.c3p0.timeout" value="300"/> <property name="hibernate.c3p0.max_statements" value="50"/> <property name="hibernate.c3p0.idle_test_period" value="300"/> </properties> </persistence-unit> </persistence>
edit 2: full stacktrace
: (a can't add stacktrace, because long). link: http://pastebin.com/lkgwqtjz
provide hibernate mapping user object in loginlog class:
example:
@manytoone(fetch = fetchtype.lazy) @joincolumn(name = "email", nullable = false) public user getuser() { return user; }
Comments
Post a Comment