java - Unknown mappedBy in: com.debatz.mistergift.model.User.token, referenced property unknown: com.debatz.mistergift.model.Token.user -
i'm not able solve new exception when deploy war tomcat 8 (using mvn tomcat:run-war command).
here pasted exception:
grave: exception sending context initialized event listener instance of class org.springframework.web.context.contextloaderlistener org.springframework.beans.factory.beancreationexception: error creating bean name 'mg-em-default' defined in class path resource [web-inf/data-context.xml]: invocation of init method failed; nested exception javax.persistence.persistenceexception: [persistenceunit: mistergift_pu] unable build hibernate sessionfactory @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1566) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:539) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:476) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:302) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:298) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:193) @ org.springframework.context.support.abstractapplicationcontext.getbean(abstractapplicationcontext.java:956) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:747) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:480) @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:403) @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:306) @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:106) @ org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4939) @ org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5434) @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150) @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1559) @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1549) @ java.util.concurrent.futuretask.run(futuretask.java:266) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ java.lang.thread.run(thread.java:745) caused by: javax.persistence.persistenceexception: [persistenceunit: mistergift_pu] unable build hibernate sessionfactory @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl.persistenceexception(entitymanagerfactorybuilderimpl.java:1225) @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl.access$600(entitymanagerfactorybuilderimpl.java:119) @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl$4.perform(entitymanagerfactorybuilderimpl.java:853) @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl$4.perform(entitymanagerfactorybuilderimpl.java:843) @ org.hibernate.boot.registry.classloading.internal.classloaderserviceimpl.withtccl(classloaderserviceimpl.java:397) @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl.build(entitymanagerfactorybuilderimpl.java:842) @ org.springframework.orm.jpa.vendor.springhibernatejpapersistenceprovider.createcontainerentitymanagerfactory(springhibernatejpapersistenceprovider.java:60) @ org.springframework.orm.jpa.localcontainerentitymanagerfactorybean.createnativeentitymanagerfactory(localcontainerentitymanagerfactorybean.java:343) @ org.springframework.orm.jpa.abstractentitymanagerfactorybean.afterpropertiesset(abstractentitymanagerfactorybean.java:318) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1625) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1562) ... 21 more
caused by: org.hibernate.annotationexception: unknown mappedby in: com.debatz.mistergift.model.user.token, referenced property unknown: com.debatz.mistergift.model.token.user @ org.hibernate.cfg.onetoonesecondpass.dosecondpass(onetoonesecondpass.java:160) @ org.hibernate.cfg.configuration.originalsecondpasscompile(configuration.java:1695) @ org.hibernate.cfg.configuration.secondpasscompile(configuration.java:1424) @ org.hibernate.cfg.configuration.buildsessionfactory(configuration.java:1844) @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl$4.perform(entitymanagerfactorybuilderimpl.java:850) ... 29 more
and 2 entities (without getters/setters):
@entity @table(schema = "mistergift", name = "users") public class user { /** * user id. */ @id @generatedvalue(strategy = generationtype.auto) private long id; /** * user first name. */ @column(name = "first_name", length = 255, nullable = false) private string firstname; /** * user last name. */ @column(name = "last_name", length = 255, nullable = false) private string lastname; /** * user email. */ @column(name = "email", length = 100, nullable = false) private string email; /** * user password. */ @column(name = "password", length = 255, nullable = false) private string password; /** user role. */ @column(name = "role", nullable = false) @enumerated(enumtype.ordinal) private role role; /** user token. */ @onetoone(mappedby = "user") private token token; /** * */ public user() { this.groups = new arraylist<group>(); } // ...
and...
@entity @table(schema = "mistergift", name = "user_token") public class token { @id @generatedvalue(generator = "uuid") @genericgenerator(name = "uuid", strategy = "uuid2") @column(name = "value", length = 75, nullable = false) private string value; @column(name = "expiration_date", nullable = false) @temporal(temporaltype.date) private date expirationdate; @onetoone(mappedby = "token") private user user; /** * */ public token() { } // ...
can please give me advice solve issue?
thanks.
you can't use mappedby
on both sides of association.
it incorrect
/** user token. */ @onetoone(mappedby = "user") private token token; @onetoone(mappedby = "token") private user user;
firstly, should decide persistent owner of association ( table have foreign key). example, if user
have foreign key column fk_token
token
identifier
@entity @table(schema = "mistergift", name = "users") public class user { /** user token. */ @onetoone @joincolumn(name = "fk_token") private token token; } @entity @table(schema = "mistergift", name = "user_token") public class token { @onetoone(mappedby = "token", fetch = fetchtype.lazy) private user user; }
if token
have foreign key column fk_user
user
identifier
@entity @table(schema = "mistergift", name = "users") public class user { /** user token. */ @onetoone(mappedby = "user") private token token; } @entity @table(schema = "mistergift", name = "user_token") public class token { @onetoone(fetch = fetchtype.lazy) @joincolumn(name = "fk_user") private user user; }
updated
the exception rised @ line onetoonesecondpass.dosecondpass(map)
because of othersideproperty == null
. hibernate try find token.user
property among persistent classes known him , fail. hibernate doesn't consider token
persistent. reasons can be
token
doesn't have@entity
annotation.token
not mapped inhibernate.cfg.xml
.incorrect scanning of packages persistents, @magik reported.
hibernate, has unclear and, may be, incorrect error message issue.
Comments
Post a Comment