java - Failed having default tenant to connect to a Multi-tenant application -
i want migrate existing single-tenant application multi-tenant application.
first step create default tenant , connect application, code following:
the model :
@entity @multitenant(multitenanttype.table_per_tenant) @tenanttablediscriminator(type = schema, contextproperty = multitenant_property_default) @table(name = "utilisateur") public class user implements serializable { @sequencegenerator(name = "user_seq", sequencename = "user_seq", allocationsize = 1) @generatedvalue(strategy = generationtype.sequence, generator = "user_seq") @column(name = "id", nullable = false) private integer id; private string username; private string password; @manytomany @jointable(name = "user_roles", joincolumns = { @joincolumn(name = "user_userid")}, inversejoincolumns = { @joincolumn(name = "role_roleid")}) private list<role> roles; ..... } @entity @multitenant(multitenanttype.table_per_tenant) @tenanttablediscriminator(type = schema, contextproperty = multitenant_property_default) public class role implements serializable { @id @sequencegenerator(name = "role_seq", sequencename = "role_seq", allocationsize = 1) @generatedvalue(strategy = generationtype.sequence, generator = "role_seq") @column(name = "id", nullable = false) private integer id; private string private string rolename; @manytomany(mappedby = "roles") private list<user> users; public integer getid() { return id; } ....}
the persistence.xml file:
<?xml version="1.0" encoding="utf-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="com.nz_war_1.0-snapshotpu" transaction-type="jta"> <provider>org.eclipse.persistence.jpa.persistenceprovider</provider> <jta-data-source>jdbc/simplecrud_jdbc</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <property name="eclipselink.logging.level" value="fine" /> <property name="eclipselink.tenant-id" value="default_tenant" /> </properties> </persistence-unit> </persistence>
i created singleton class have entity manager factory:
public class emfprovider { private static final string db_pu = "com.nz_war_1.0-snapshotpu"; public static final boolean debug = true; private static final emfprovider singleton = new emfprovider(); private entitymanagerfactory emf; private emfprovider() { } public static emfprovider getinstance() { return singleton; } public entitymanagerfactory getentitymanagerfactory() { if (emf == null) { emf = persistence.createentitymanagerfactory(db_pu); } if (debug) { system.out.println("factory created on: " + new date()); } return emf; } public void closeemf() { if (emf.isopen() || emf != null) { emf.close(); } emf = null; if (debug) { system.out.println("emf closed at: " + new date()); } } }
the facade: note don't user @persistencecontext, , create entitymanager using persistence unit manually because later have deterimine persistenceuunit use programaticly:
public abstract class dataaccessservice<t> { private entitymanager em; public dataaccessservice() {} private class<t> type; public dataaccessservice(class<t> type) { this.type = type; } public void create(t t) { em = emfprovider.getinstance().getentitymanagerfactory().createentitymanager(); this.em.persist(t); this.em.flush(); this.em.refresh(t); public list findwithnamedquery(string namedqueryname) { em = emfprovider.getinstance().getentitymanagerfactory().createentitymanager(); return this.em.createnamedquery(namedqueryname).getresultlist(); } .......... }
@stateless
public class userservice extends dataaccessservice<user>{ public userservice(){ super(user.class); } }
after running project exception is: predeployment of persistenceunit [com.nz_war_1.0-snapshotpu] failed.
, long error in glassfish log:
avertissement: ejb5184:a system exception occurred during invocation on ejb userservice, method: public java.util.list com.nz.simplecrud.service.dataaccessservice.findwithnamedquery(java.lang.string) avertissement: javax.ejb.ejbexception @ com.sun.ejb.containers.basecontainer.processsystemexception(basecontainer.java:5215) @ com.sun.ejb.containers.basecontainer.completenewtx(basecontainer.java:5113) @ com.sun.ejb.containers.basecontainer.postinvoketx(basecontainer.java:4901) @ com.sun.ejb.containers.basecontainer.postinvoke(basecontainer.java:2045) @ com.sun.ejb.containers.basecontainer.postinvoke(basecontainer.java:1994) @ com.sun.ejb.containers.ejblocalobjectinvocationhandler.invoke(ejblocalobjectinvocationhandler.java:222) @ com.sun.ejb.containers.ejblocalobjectinvocationhandlerdelegate.invoke(ejblocalobjectinvocationhandlerdelegate.java:89) @ com.sun.proxy.$proxy284.findwithnamedquery(unknown source) @ com.nz.simplecrud.service.__ejb31_generated__userservice__intf____bean__.findwithnamedquery(unknown source) @ 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.jboss.weld.util.reflection.securereflections$13.work(securereflections.java:267) @ org.jboss.weld.util.reflection.securereflectionaccess.run(securereflectionaccess.java:52) @ org.jboss.weld.util.reflection.securereflectionaccess.runasinvocation(securereflectionaccess.java:137) @ org.jboss.weld.util.reflection.securereflections.invoke(securereflections.java:263) @ org.jboss.weld.bean.proxy.enterprisebeanproxymethodhandler.invoke(enterprisebeanproxymethodhandler.java:110) @ org.jboss.weld.bean.proxy.enterprisetargetbeaninstance.invoke(enterprisetargetbeaninstance.java:56) @ org.jboss.weld.bean.proxy.proxymethodhandler.invoke(proxymethodhandler.java:105) @ com.nz.simplecrud.service.userservice$proxy$_$$_weld$proxy$.findwithnamedquery(userservice$proxy$_$$_weld$proxy$.java) @ com.nz.simplecrud.controller.usercontroller.init(usercontroller.java:64) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) ...... caused by: exception [eclipselink-30005] (eclipse persistence services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.persistenceunitloadingexception exception description: exception thrown while searching persistence archives classloader: webappclassloader (delegate=true; repositories=web-inf/classes/) internal exception: javax.persistence.persistenceexception: exception [eclipselink-28018] (eclipse persistence services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.entitymanagersetupexception exception description: predeployment of persistenceunit [com.nz_war_1.0-snapshotpu] failed. internal exception: exception [eclipselink-7161] (eclipse persistence services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.validationexception exception description: entity class [class com.nz.simplecrud.entities.userroleview] has no primary key specified. should define either @id, @embeddedid or @idclass. if have defined pk using of these annotations make sure not have mixed access-type (both fields , properties annotated) in entity class hierarchy. @ org.eclipse.persistence.exceptions.persistenceunitloadingexception.exceptionsearchingforpersistenceresources(persistenceunitloadingexception.java:127) @ org.eclipse.persistence.jpa.persistenceprovider.createentitymanagerfactoryimpl(persistenceprovider.java:111) @ org.eclipse.persistence.jpa.persistenceprovider.createentitymanagerfactory(persistenceprovider.java:183) .... caused by: javax.persistence.persistenceexception: exception [eclipselink-28018] (eclipse persistence services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.entitymanagersetupexception exception description: predeployment of persistenceunit [com.nz_war_1.0-snapshotpu] failed. internal exception: exception [eclipselink-7161] (eclipse persistence services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.validationexception exception description: entity class [class com.nz.simplecrud.entities.userroleview] has no primary key specified. should define either @id, @embeddedid or @idclass. if have defined pk using of these annotations make sure not have mixed access-type (both fields , properties annotated) in entity class hierarchy. @ org.eclipse.persistence.internal.jpa.entitymanagersetupimpl.createpredeployfailedpersistenceexception(entitymanagersetupimpl.java:2023) @ org.eclipse.persistence.internal.jpa.entitymanagersetupimpl.predeploy(entitymanagersetupimpl.java:2014) caused by: exception [eclipselink-28018] (eclipse persistence services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.entitymanagersetupexception exception description: predeployment of persistenceunit [com.nz_war_1.0-snapshotpu] failed. internal exception: exception [eclipselink-7161] (eclipse persistence services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.validationexception exception description: entity class [class com.nz.simplecrud.entities.userroleview] has no primary key specified. should define either @id, @embeddedid or @idclass. if have defined pk using of these annotations make sure not have mixed access-type (both fields , properties annotated) in entity class hierarchy. @ org.eclipse.persistence.exceptions.entitymanagersetupexception.predeployfailed(entitymanagersetupexception.java:231) ... 135 more caused by: exception [eclipselink-7161] (eclipse persistence services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.validationexception exception description: entity class [class com.nz.simplecrud.entities.userroleview] has no primary key specified. should define either @id, @embeddedid or @idclass. if have defined pk using of these annotations make sure not have mixed access-type (both fields , properties annotated) in entity class hierarchy. @ org.eclipse.persistence.exceptions.validationexception.noprimarykeyannotationsfound(validationexception.java:1425) grave: error rendering view[/admin/userlist.xhtml] javax.el.elexception: /admin/userlist.xhtml @12,69 value="#{usercontroller.lazymodel}": org.jboss.weld.exceptions.weldexception: weld-000049 unable invoke [method] @postconstruct public com.nz.simplecrud.controller.usercontroller.init() on com.nz.simplecrud.controller.usercontroller@519c628d @ com.sun.faces.facelets.el.tagvalueexpression.getvalue(tagvalueexpression.java:114) @ javax.faces.component.componentstatehelper.eval(componentstatehelper.java:194) @ javax.faces.component.componentstatehelper.eval(componentstatehelper.java:182).... grave: error rendering view[/admin/userlist.xhtml] javax.el.elexception: /admin/userlist.xhtml @12,69 value="#{usercontroller.lazymodel}": org.jboss.weld.exceptions.weldexception: weld-000049 unable invoke [method] @postconstruct public com.nz.simplecrud.controller.usercontroller.init() on com.nz.simplecrud.controller.usercontroller@5bcd013b @ com.sun.faces.facelets.el.tagvalueexpression.getvalue(tagvalueexpression.java:114) @ javax.faces.component.componentstatehelper.eval(componentstatehelper.java:194) @ javax.faces.component.componentstatehelper.eval(componentstatehelper.java:182) @ javax.faces.component.uidata.getvalue(uidata.java:731).... caused by: org.jboss.weld.exceptions.weldexception: weld-000049 unable invoke [method] @postconstruct public com.nz.simplecrud.controller.usercontroller.init() on com.nz.simplecrud.controller.usercontroller@5bcd013b @ org.jboss.weld.bean.abstractclassbean.defaultpostconstruct(abstractclassbean.java:400) @ org.jboss.weld.bean.managedbean$managedbeaninjectiontarget.postconstruct(managedbean.java:174) @ org.jboss.weld.bean.managedbean.create(managedbean.java:294) @ org.jboss.weld.context.abstractcontext.get(abstractcontext.java:107)
can 1 me please. thank you.
Comments
Post a Comment