websphere - How do I write a JPA primary key generator that will work for several databases and several app servers? -
i'm on project (java/ejb/jpa swing client) deployed several different app servers , supports several different databases. application required run on combination of following servers , databases:
servers: - glassfish - jboss - websphere (was) databases: - oracle - mysql - microsoft sql server
is there 1 way generate primary key using jpa work in of these environments. have tried number of different strategies , have gotten farthest using annotation in jpa entity class:
@id @column( name = "id" ) @tablegenerator( name = "appseqstore", table = "app_seq_store", pkcolumnname = "app_seq_name", pkcolumnvalue = "listener_pk", valuecolumnname = "app_seq_value", initialvalue = 1, allocationsize = 1 ) @generatedvalue( strategy = generationtype.table, generator = "appseqstore" )
and table in database:
create table app_seq_store ( app_seq_name varchar(255) not null, app_seq_value number(10) not null, primary key(app_seq_name) ) insert app_seq_store values ('listener_pk', 0)
this works in oracle, , ms sql server, , mysql using jboss app server. in other words works of databases i've tried using jboss.
this not work in webspehere (was 8.5.5.2) , gives following exception (oracle database in case):
[4/24/15 22:29:17:339 edt] 00000079 businessexcep e cntr0020e: ejb threw unexpected (non-declared) exception during invocation of method "addnewlistenertarget" on bean "beanid(myappwas#myappserverejb.jar#listenerdaoejb, null)". exception data: java.lang.unsupportedoperationexception @ org.hibernate.service.jta.platform.internal.websphereextendedjtaplatform$transactionmanageradapter.setrollbackonly(websphereextendedjtaplatform.java:139) @ org.hibernate.ejb.abstractentitymanagerimpl.markasrollback(abstractentitymanagerimpl.java:1169) @ org.hibernate.ejb.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1319) @ org.hibernate.ejb.abstractentitymanagerimpl.persist(abstractentitymanagerimpl.java:881) @ com.ibm.ws.jpa.management.jpaexeminvocation.persist(jpaexeminvocation.java:317) @ com.ibm.ws.jpa.management.jpaentitymanager.persist(jpaentitymanager.java:143) @ com.apelon.server.ejb.listenerdaobean.addnewlistenertarget(listenerdaobean.java:243) @ com.apelon.server.dao.remote.ejsremote0sllistenerdaoejb_446f2106.addnewlistenertarget(ejsremote0sllistenerdaoejb_446f2106.java) @ com.apelon.server.dao.remote._ejsremote0sllistenerdaoejb_446f2106_tie.addnewlistenertarget(_ejsremote0sllistenerdaoejb_446f2106_tie.java:1) @ com.apelon.server.dao.remote._ejsremote0sllistenerdaoejb_446f2106_tie._invoke(_ejsremote0sllistenerdaoejb_446f2106_tie.java) @ com.ibm.corba.iiop.serverdelegate.dispatchinvokehandler(serverdelegate.java:678) @ com.ibm.corba.iiop.serverdelegate.dispatch(serverdelegate.java:525) @ com.ibm.rmi.iiop.orb.process(orb.java:616) @ com.ibm.corba.iiop.orb.process(orb.java:1581) @ com.ibm.rmi.iiop.connection.dorequestwork(connection.java:3160) @ com.ibm.rmi.iiop.connection.dowork(connection.java:3030) @ com.ibm.rmi.iiop.workunitimpl.dowork(workunitimpl.java:64) @ com.ibm.ejs.oa.pool.pooledthread.run(threadpool.java:118) @ com.ibm.ws.util.threadpool$worker.run(threadpool.java:1864)
Comments
Post a Comment