java - JPA: store OneToMany-Relationship into a map -
i have problems storing onetomany-relationship map. use jpa/hibernate spring.
this code:
@table(name = "room_member", uniqueconstraints = @uniqueconstraint( columnnames = { "room", "member" })) public class roommember { @id @generatedvalue(strategy = generationtype.table) private long id; @manytoone(optional = false) @joincolumn(name = "room") private room room; @manytoone(optional = false) @joincolumn(name = "member") private member member; // getters , setters omitted }
the class want map:
public room { @id @generatedvalue(strategy = generationtype.table) private long id; @onetomany(mappedby = "room") @mapkeyjoincolumn(name = "member") private map<member, roommember> roommember; // getters , setters omitted }
i cant running, because nullpointerexception
org.springframework.beans.factory.beancreationexception: error creating bean name 'entitymanagerfactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/hibernatejpaautoconfiguration.class]: invocation of init method failed; nested exception java.lang.nullpointerexception @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1628) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:555) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:483) @ 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:1081) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:856) @ org.springframework.context.support.abstractapplicationcontext.__refresh(abstractapplicationcontext.java:542) @ org.springframework.context.support.abstractapplicationcontext.jrlockandrefresh(abstractapplicationcontext.java) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java) @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.refresh(embeddedwebapplicationcontext.java:122) @ org.springframework.boot.springapplication.refresh(springapplication.java:737) @ org.springframework.boot.springapplication.refreshcontext(springapplication.java:370) @ org.springframework.boot.springapplication.run(springapplication.java:314) @ de.swr.eva.eventanwendungapplication.main(eventanwendungapplication.java:40) caused by: java.lang.nullpointerexception: null @ org.hibernate.envers.configuration.internal.metadata.collectionmetadatagenerator.addvaluetomiddletable(collectionmetadatagenerator.java:567) @ org.hibernate.envers.configuration.internal.metadata.collectionmetadatagenerator.addindex(collectionmetadatagenerator.java:477) @ org.hibernate.envers.configuration.internal.metadata.collectionmetadatagenerator.addonetomanyattached(collectionmetadatagenerator.java:212) @ org.hibernate.envers.configuration.internal.metadata.collectionmetadatagenerator.addcollection(collectionmetadatagenerator.java:157) @ org.hibernate.envers.configuration.internal.metadata.auditmetadatagenerator.addvalueinsecondpass(auditmetadatagenerator.java:321) @ org.hibernate.envers.configuration.internal.metadata.auditmetadatagenerator.addvalue(auditmetadatagenerator.java:354) @ org.hibernate.envers.configuration.internal.metadata.auditmetadatagenerator.addproperties(auditmetadatagenerator.java:374) @ org.hibernate.envers.configuration.internal.metadata.auditmetadatagenerator.generatesecondpass(auditmetadatagenerator.java:713) @ org.hibernate.envers.configuration.internal.entitiesconfigurator.configure(entitiesconfigurator.java:108) @ org.hibernate.envers.boot.internal.enversserviceimpl.doinitialize(enversserviceimpl.java:152) @ org.hibernate.envers.boot.internal.enversserviceimpl.initialize(enversserviceimpl.java:117) @ org.hibernate.envers.boot.internal.additionaljaxbmappingproducerimpl.produceadditionalmappings(additionaljaxbmappingproducerimpl.java:99) @ org.hibernate.boot.model.process.spi.metadatabuildingprocess.complete(metadatabuildingprocess.java:288) @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl.metadata(entitymanagerfactorybuilderimpl.java:848) @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl.build(entitymanagerfactorybuilderimpl.java:875) @ org.springframework.orm.jpa.vendor.springhibernatejpapersistenceprovider.__createentitymanagerfactory(springhibernatejpapersistenceprovider.java:60) @ org.springframework.orm.jpa.vendor.springhibernatejpapersistenceprovider.createcontainerentitymanagerfactory(springhibernatejpapersistenceprovider.java) @ org.springframework.orm.jpa.localcontainerentitymanagerfactorybean.__createnativeentitymanagerfactory(localcontainerentitymanagerfactorybean.java:353) @ org.springframework.orm.jpa.localcontainerentitymanagerfactorybean.createnativeentitymanagerfactory(localcontainerentitymanagerfactorybean.java) @ org.springframework.orm.jpa.abstractentitymanagerfactorybean.buildnativeentitymanagerfactory(abstractentitymanagerfactorybean.java:373) @ org.springframework.orm.jpa.abstractentitymanagerfactorybean.afterpropertiesset(abstractentitymanagerfactorybean.java:362) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1687) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1624) ... 16 common frames omitted
it works, if use id key:
@onetomany(mappedby = "room") @mapkey(name = "id") private map<string, roommember> roommember;
but need member map key. ofc build map manually, think should work automatically.
this 1 works expected:
@onetomany(mappedby = "room") private set<roommember> roommember;
can see failure , give me hint?
best wishes!
wizo
Comments
Post a Comment