java - setting up one to many relationship using Hibernate, JPA -


i trying setup 1 many relationship using hibernate/jpa.

currently getting exception:

invocation of init method failed; nested exception org.hibernate.hibernateexception: missing table: refund_transaction_item_refund_detail     @ 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:305)     @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230)     @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:301)     @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:196)     @ org.springframework.context.support.abstractapplicationcontext.getbean(abstractapplicationcontext.java:1045)     @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:824)     @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:537)     @ 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.startcontext(contexthandler.java:746)     @ org.eclipse.jetty.servlet.servletcontexthandler.startcontext(servletcontexthandler.java:238)     @ org.eclipse.jetty.webapp.webappcontext.startcontext(webappcontext.java:1238)     @ org.eclipse.jetty.server.handler.contexthandler.dostart(contexthandler.java:689)     @ org.eclipse.jetty.webapp.webappcontext.dostart(webappcontext.java:480)     @ org.mortbay.jetty.plugin.jettywebappcontext.dostart(jettywebappcontext.java:256)     @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:64)     @ org.eclipse.jetty.server.handler.handlercollection.dostart(handlercollection.java:229)     @ org.eclipse.jetty.server.handler.contexthandlercollection.dostart(contexthandlercollection.java:172)     @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:64)     @ org.eclipse.jetty.server.handler.handlercollection.dostart(handlercollection.java:229)     @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:64)     @ org.eclipse.jetty.server.handler.handlerwrapper.dostart(handlerwrapper.java:95)     @ org.eclipse.jetty.server.server.dostart(server.java:279)     @ org.mortbay.jetty.plugin.jettyserver.dostart(jettyserver.java:65)     @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:64)     @ org.mortbay.jetty.plugin.abstractjettymojo.startjetty(abstractjettymojo.java:520)     @ org.mortbay.jetty.plugin.abstractjettymojo.execute(abstractjettymojo.java:365)     @ org.mortbay.jetty.plugin.jettyrunwarmojo.execute(jettyrunwarmojo.java:71)     @ org.apache.maven.plugin.defaultbuildpluginmanager.executemojo(defaultbuildpluginmanager.java:132)     @ org.apache.maven.lifecycle.internal.mojoexecutor.execute(mojoexecutor.java:208)     @ 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:116)     @ org.apache.maven.lifecycle.internal.lifecyclemodulebuilder.buildproject(lifecyclemodulebuilder.java:80)     @ org.apache.maven.lifecycle.internal.builder.singlethreaded.singlethreadedbuilder.build(singlethreadedbuilder.java:51)     @ org.apache.maven.lifecycle.internal.lifecyclestarter.execute(lifecyclestarter.java:120)     @ org.apache.maven.defaultmaven.doexecute(defaultmaven.java:347)     @ org.apache.maven.defaultmaven.execute(defaultmaven.java:154)     @ org.apache.maven.cli.mavencli.execute(mavencli.java:582)     @ org.apache.maven.cli.mavencli.domain(mavencli.java:214)     @ org.apache.maven.cli.mavencli.main(mavencli.java:158)     @ 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:289)     @ org.codehaus.plexus.classworlds.launcher.launcher.launch(launcher.java:229)     @ org.codehaus.plexus.classworlds.launcher.launcher.mainwithexitcode(launcher.java:415)     @ org.codehaus.plexus.classworlds.launcher.launcher.main(launcher.java:356) caused by: org.hibernate.hibernateexception: missing table: refund_transaction_item_refund_detail     @ org.hibernate.cfg.configuration.validateschema(configuration.java:1333)     @ org.hibernate.tool.hbm2ddl.schemavalidator.validate(schemavalidator.java:155)     @ org.hibernate.internal.sessionfactoryimpl.<init>(sessionfactoryimpl.java:525)     @ org.hibernate.cfg.configuration.buildsessionfactory(configuration.java:1857)     @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl$4.perform(entitymanagerfactorybuilderimpl.java:850)     @ 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:1637)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1574)     @ 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:305)     @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230)     @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:301)     @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:196)     @ org.springframework.context.support.abstractapplicationcontext.getbean(abstractapplicationcontext.java:1045)     @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:824)     @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:537)     @ 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.startcontext(contexthandler.java:746)     @ org.eclipse.jetty.servlet.servletcontexthandler.startcontext(servletcontexthandler.java:238)     @ org.eclipse.jetty.webapp.webappcontext.startcontext(webappcontext.java:1238)     @ org.eclipse.jetty.server.handler.contexthandler.dostart(contexthandler.java:689)     @ org.eclipse.jetty.webapp.webappcontext.dostart(webappcontext.java:480)     @ org.mortbay.jetty.plugin.jettywebappcontext.dostart(jettywebappcontext.java:256)     @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:64)     @ org.eclipse.jetty.server.handler.handlercollection.dostart(handlercollection.java:229)     @ org.eclipse.jetty.server.handler.contexthandlercollection.dostart(contexthandlercollection.java:172)     @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:64)     @ org.eclipse.jetty.server.handler.handlercollection.dostart(handlercollection.java:229)     @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:64)     @ org.eclipse.jetty.server.handler.handlerwrapper.dostart(handlerwrapper.java:95)     @ org.eclipse.jetty.server.server.dostart(server.java:279)     @ org.mortbay.jetty.plugin.jettyserver.dostart(jettyserver.java:65)     @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:64)     @ org.mortbay.jetty.plugin.abstractjettymojo.startjetty(abstractjettymojo.java:520)     @ org.mortbay.jetty.plugin.abstractjettymojo.execute(abstractjettymojo.java:365)     @ org.mortbay.jetty.plugin.jettyrunwarmojo.execute(jettyrunwarmojo.java:71)     @ org.apache.maven.plugin.defaultbuildpluginmanager.executemojo(defaultbuildpluginmanager.java:132)     @ org.apache.maven.lifecycle.internal.mojoexecutor.execute(mojoexecutor.java:208)     @ 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:116)     @ org.apache.maven.lifecycle.internal.lifecyclemodulebuilder.buildproject(lifecyclemodulebuilder.java:80)     @ org.apache.maven.lifecycle.internal.builder.singlethreaded.singlethreadedbuilder.build(singlethreadedbuilder.java:51)     @ org.apache.maven.lifecycle.internal.lifecyclestarter.execute(lifecyclestarter.java:120)     @ org.apache.maven.defaultmaven.doexecute(defaultmaven.java:347)     @ org.apache.maven.defaultmaven.execute(defaultmaven.java:154)     @ org.apache.maven.cli.mavencli.execute(mavencli.java:582)     @ org.apache.maven.cli.mavencli.domain(mavencli.java:214)     @ org.apache.maven.cli.mavencli.main(mavencli.java:158)     @ 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:289)     @ org.codehaus.plexus.classworlds.launcher.launcher.launch(launcher.java:229)     @ org.codehaus.plexus.classworlds.launcher.launcher.mainwithexitcode(launcher.java:415)     @ org.codehaus.plexus.classworlds.launcher.launcher.main(launcher.java:356) 

refundtransaction.java parent class

import java.util.date; import java.util.set;  import javax.persistence.cascadetype; import javax.persistence.column; import javax.persistence.elementcollection; import javax.persistence.entity; import javax.persistence.fetchtype; import javax.persistence.generatedvalue; import javax.persistence.id; import javax.persistence.joincolumn; import javax.persistence.onetomany; import javax.persistence.table; import javax.persistence.temporal; import javax.persistence.temporaltype;  import org.hibernate.annotations.genericgenerator;  import com.limeroad.commons.refundrequest;   @entity @table(name = "refund_transaction") public class refundtransaction {    public refundtransaction() {}    public refundtransaction(refundrequest refundrequest) {     setorderid(refundrequest.getorderid());     setrefundreason(refundrequest.getrefundreason());     setcallbackurl(refundrequest.getcallbackurl());     setcreatedby(refundrequest.getcreatedby());     setidempotencekey(refundrequest.getclientname() + ":" + refundrequest.getclientkey());   }    @elementcollection(targetclass = itemrefunddetail.class)   set<itemrefunddetail> itemrefunddetails;    @onetomany(fetch = fetchtype.eager, cascade = {cascadetype.all})   @joincolumn(name = "refund_request_id", referencedcolumnname = "refund_request_id" )   public set<itemrefunddetail> getitemrefunddetails() {     return itemrefunddetails;   }    public void setitemrefunddetails(set<itemrefunddetail> itemrefunddetails) {     this.itemrefunddetails = itemrefunddetails;   }    @column(name = "refund_reason")   string refundreason;    @column(name = "callback_url")   string callbackurl;    @column(name = "order_id")   string orderid;    @id   @generatedvalue(generator = "system-uuid")   @genericgenerator(name = "system-uuid", strategy = "com.limeroad.services.payments.factory.limeroadidgenerator")   @column(name = "refund_request_id")   string refundrequestid;    @column(name = "idempotence_key")   string idempotencekey;    @column(name = "created_by")   string createdby;    @column(name = "modified_by")   string modifiedby;    @temporal(temporaltype.timestamp)   @column(name = "create_date")   date createdate;    @temporal(temporaltype.timestamp)   @column(name = "last_modified")   date lastmodified;    @column(name = "refund_reason")   public string getrefundreason() {     return refundreason;   }    @column(name = "callback_url")   public string getcallbackurl() {     return callbackurl;   }    @column(name = "order_id")   public string getorderid() {     return orderid;   }    @column(name = "refund_request_id")   public string getrefundrequestid() {     return refundrequestid;   }    @column(name = "idempotence_key")   public string getidempotencekey() {     return idempotencekey;   }    @column(name = "created_by")   public string getcreatedby() {     return createdby;   }    @column(name = "modified_by")   public string getmodifiedby() {     return modifiedby;   }    @temporal(temporaltype.timestamp)   @column(name = "last_modified")   public date getcreatedate() {     return createdate;   }    @temporal(temporaltype.timestamp)   @column(name = "last_modified")   public date getlastmodified() {     return lastmodified;   }    public void setrefundreason(string refundreason) {     this.refundreason = refundreason;   }    public void setcallbackurl(string callbackurl) {     this.callbackurl = callbackurl;   }    public void setorderid(string orderid) {     this.orderid = orderid;   }    public void setrefundrequestid(string refundrequestid) {     this.refundrequestid = refundrequestid;   }    public void setidempotencekey(string idempotencekey) {     this.idempotencekey = idempotencekey;   }    public void setcreatedby(string createdby) {     this.createdby = createdby;   }    public void setmodifiedby(string modifiedby) {     this.modifiedby = modifiedby;   }    public void setcreatedate(date createdate) {     this.createdate = createdate;   }    public void setlastmodified(date lastmodified) {     this.lastmodified = lastmodified;   }    } 

itemrefunddetail.java child class.

import java.io.serializable;  import javax.persistence.column; import javax.persistence.entity; import javax.persistence.id; import javax.persistence.joincolumn; import javax.persistence.manytoone; import javax.persistence.table; import javax.persistence.transient;  @table(name = "item_refund_detail") @entity public class itemrefunddetail implements serializable {   private static final long serialversionuid = 4604092182622619714l;    refundtransaction refundtransaction;    @manytoone   @joincolumn(name="refund_request_id")   public refundtransaction getrefundtransaction() {     return refundtransaction;   }    public void setrefundtransaction(refundtransaction refundtransaction) {     this.refundtransaction = refundtransaction;   }    @id   @column(name = "order_id")   string orderid;    @id   @column(name = "unique_item_id")   string uniqueitemid;    double amount;  //  @column(name = "refund_request_id") //  string refundrequestid;    @id   @column(name = "refund_transaction_id")   string refundtransactionid;    @column(name = "transaction_ref")   string transactionref;    @transient   instrumenttype instrumenttype;    @id   @column(name = "order_id")   public string getorderid() {     return orderid;   }    @id   @column(name = "unique_item_id")   public string getuniqueitemid() {     return uniqueitemid;   }     public double getamount() {     return amount;   }  //  @column(name = "refund_request_id") //  public string getrefundrequestid() { //    return refundrequestid; //  }    @id   @column(name = "refund_transaction_id")   public string getrefundtransactionid() {     return refundtransactionid;   }    @column(name = "transaction_ref")   public string gettransactionref() {     return transactionref;   }    @transient   public instrumenttype getinstrumenttype() {     return instrumenttype;   }    public void setorderid(string orderid) {     this.orderid = orderid;   }    public void setuniqueitemid(string uniqueitemid) {     this.uniqueitemid = uniqueitemid;   }    public void setamount(double amount) {     this.amount = amount;   }  //  public void setrefundrequestid(string refundrequestid) { //    this.refundrequestid = refundrequestid; //  }    public void setrefundtransactionid(string refundtransactionid) {     this.refundtransactionid = refundtransactionid;   }    public void settransactionref(string transactionref) {     this.transactionref = transactionref;   }    public void setinstrumenttype(instrumenttype instrumenttype) {     this.instrumenttype = instrumenttype;   }    } 

i know making mistake in @onetomany or @manytoone annotation.

update: have 2 tables in db, refund_transaction , item_refund_detail. , dont't have table named refund_transaction_item_refund_detail. after normalizing schema, have added refund_request_id in item_refund_detail table maintaining relationship. need maintain unidirectional mapping, achieve this. please advice.

you're doing many things wrong. of points:

  1. you're using both field , property access. have pick 1 style default (you can override default accesstype desired properties).
  2. @elementcollection used embedded collections, hence error get. should use @onetomany this.
  3. don't forget declare 1 side of bidirectional association inverse 1 (in case of @onetomany relation, that's entity on one side).

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -