spring-data


JtaPlatformInaccessibleException: Unable to access TransactionManager or UserTransaction to make physical transaction delegate


I am trying to implement JTA for performing a transaction across two database table.
I have below code to specify entityManager, transactionManager and datasource
#Bean(name = "EntityMF1")
public LocalContainerEntityManagerFactoryBean EntityMF1() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setPersistenceUnitName("EntityMF1");
em.setBeanName("EntityMF1");
em.setJtaDataSource(DS1());
em.setPackagesToScan(new String[] { "com.abc.domain.events" });
em.setPersistenceProvider(new HibernatePersistenceProvider());
Properties p = hibernateSpecificProperties();
p.setProperty("hibernate.ejb.entitymanager_factory_name", "EntityMF1");
em.setJpaProperties(p);
return em;
}
#Bean(name = "database1")
public MysqlXADataSource database1() {
MysqlXADataSource dataSource = new MysqlXADataSource();
dataSource.setUrl(env.getProperty(DB_URL_KEY));
dataSource.setUser(env.getProperty(DB_USER_KEY));
dataSource.setPassword(env.getProperty(DB_PASSWORD_KEY));
dataSource.setPinGlobalTxToPhysicalConnection(true);
return dataSource;
}
#Bean(name = "DS1")
public DataSource DS1() {
AtomikosDataSourceBean bean = new AtomikosDataSourceBean();
bean.setUniqueResourceName("DS1");
bean.setXaDataSource(Database1());
bean.setPoolSize(3);
return bean;
}
#Bean(name="atomikosTransactionManager")
public UserTransactionManager atomikosTransactionManager(){
UserTransactionManager userTransactionManager = new UserTransactionManager();
userTransactionManager.setForceShutdown(false);
AtomikosJtaPlatform.transactionManager = userTransactionManager;
return userTransactionManager;
}
#Bean(name="atomikosUserTransaction")
public UserTransaction atomikosUserTransaction() throws Throwable {
UserTransactionImp map = new UserTransactionImp();
map.setTransactionTimeout(300);
return map;
}
#Bean(name="transactionManager1")
public PlatformTransactionManager transactionManager1() throws Throwable {
UserTransaction userTransaction = atomikosUserTransaction();
AtomikosJtaPlatform.transaction = userTransaction;
TransactionManager atomikosTransactionManager = atomikosTransactionManager();
return new JtaTransactionManager(userTransaction, atomikosTransactionManager);
}
the above code throws below error:
Caused by: org.hibernate.resource.transaction.backend.jta.internal.JtaPlatformInaccessibleException: Unable to access TransactionManager or UserTransaction to make physical transaction delegate
at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.makePhysicalTransactionDelegate(JtaTransactionCoordinatorImpl.java:229)
at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.getTransactionDriverControl(JtaTransactionCoordinatorImpl.java:203)
at org.hibernate.engine.transaction.internal.TransactionImpl.<init>(TransactionImpl.java:36)
at org.hibernate.internal.AbstractSessionImpl.getTransaction(AbstractSessionImpl.java:313)
at org.hibernate.internal.SessionImpl.<init>(SessionImpl.java:278)
at org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl.openSession(SessionFactoryImpl.java:1332)
at org.hibernate.jpa.internal.EntityManagerImpl.internalGetSession(EntityManagerImpl.java:133)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:174)
at org.hibernate.jpa.internal.EntityManagerImpl.<init>(EntityManagerImpl.java:83)
at org.hibernate.jpa.internal.EntityManagerFactoryImpl.internalCreateEntityManager(EntityManagerFactoryImpl.java:319)
at org.hibernate.jpa.internal.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:286)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.invokeProxyMethod(AbstractEntityManagerFactoryBean.java:459)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean$ManagedEntityManagerFactoryInvocationHandler.invoke(AbstractEntityManagerFactoryBean.java:630)
at com.sun.proxy.$Proxy38.createEntityManager(Unknown Source)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:292)
at com.sun.proxy.$Proxy55.getDelegate(Unknown Source)
at org.springframework.data.jpa.provider.PersistenceProvider.fromEntityManager(PersistenceProvider.java:303)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.<init>(JpaRepositoryFactory.java:59)
Can anyone please help.

Related Links

spring data load children and query by child property
What is the difference between all these spring DAO templates
Spring Batch and Neo4j: Transaction synchronization is not active
spring data not get id annotaion on method
spring jpa query dsl doesnt work with projection
Spring Elasticsearch data repository in Weld SE CDI - UnsatisfiedResolutionException
Spring Data query by example and Primefaces datatable filtering
spring-data-parent and spring-data-* projects with java 6?
SpringJPA + Eclipselink: No [ManagedType] was found for the key class. Not using persistance.xml
spring Batch partitioning + spring-data-mongo integration example
Trying to use Crate.io NoSql database with an existing Spring Data / Mysql project
How spring data generate sql according to method name?
Spring Data Jpa equality of two column
Spring Data Mongodb findBy In case insensitive
How to set arrays of string to #EnableJpaRepositories from property files
Java Config for Spring Gemfire xml

Categories

HOME
magento2
xcode
gaming
functional-programming
barcode-scanner
visual-studio-2010
jersey-2.0
turbojpeg
capistrano
sentry
onvif
minecraft
telegraf
kurento
graphdb
tiff
xbap
ex
jodatime
jpa-2.0
dma
synthesis
http-authentication
substring
pyopencl
dragula
webviewclient
msdeploy
tortoisehg
es6-modules
source-insight
winsock
phpstorm-2016.1
rust-cargo
fotorama
john-the-ripper
plantuml
apptentive
buildforge
android-alarms
elastica
extbase
expandablelistview
music21
sonicmq
sharpdx
asp.net-web-api-routing
word-2016
kendo-treeview
maatwebsite-excel
annotatorjs
mifos
pyaudio
cdo.message
strpos
rails-engines
okta-api
openmrs
bayesglm
godeps
place
cfwheels
espresso
postal-code
dynamics-ax-2012-r2
signed
subview
jcheckbox
lmax
visual-c++-2012
osascript
accessory
csslint
ivalueconverter
flipboard
acitree
unrealscript
libxml-js
node.js-stream
oembed
itunes-sdk
office-app
xalan
spark-view-engine
struts2-s2hibernate
series-40
nsfont
firefly-mv
directshow.net
airprint
ognl
bass
tabbarcontroller
fgetc
ning
comment-conventions
word-automation

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App