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

How can I create a Predicate from a HQL query?
Left Join in Spring Data JPA's Specification
Lombok Usage - It doesn't serve its functionality in a unit test
Spring Data Couchbase findById always returns null
spring-data-neo4j repository with Camel fails to initialize
How does pages work if the DB is manipulated between next
How can I generate Q-classes with QueryDsl 4.1.4 and Spring-Data-Jpa 2.0.0.M1?
How to map a legacy database table with mismanaged attribute names
spring-data-redis: Unexpected end of stream exception
Is it possible to use OR and LIKE keyword together in Spring Data JPA
Save and find within same transaction
Why doesn't spring-data-elasticsearch use the objectmapper from the spring context
QueryDSL 4.3.1 : Generate JPA and SQL Types using Maven
How to write MongoTemplate Query and Criteria for a complex Document structure?
Custom Implementation AuditorAware in Spring Data
Pushing more than one item in a group using push

Categories

HOME
cocoapods
xpath
macos-sierra
class
weblogic12c
windows-8.1
adfs3.0
opencv-python
barcode-scanner
filesize
theano
braintree
autocomplete
tabs
lvm
openfoam
facebook-android-sdk
stored-procedures
ag-grid
specifications
timber
jpa-criteria
stack-overflow
phpstorm-2017.1
bootstrap-switch
mailmerge
mahout-recommender
raml
opam
bosun
conda
channel
ratio
jpa-2.1
managed-c++
tortoisemerge
web-config-transform
cellular-network
window-managers
strophe.js
php-5.3
ninject
unmarshalling
mdns
intune
phpstorm-2016.1
payeezy
numerics
aurelia-cli
grails-spring-security
resampling
django-static-precompiler
sonatype
1010
msxml
oracle-fusion-apps
boost-compute
google-identity-toolkit
okio
clp
nunit-console
nvda
always-on-top
gnucash
android-syncadapter
flush
textpattern
opencyc
cfwheels
netdatacontractserializer
darwin
textscan
physicsjs
scala-macros
uno
n-tier-architecture
utf8-decode
cout
adwords-apiv201402
category-theory
treeline
hyperloglog
commenting
visual-c++-2005
stty
lru
sly-scroller
html-frames
ui-design
jbox2d
chronometer
voice-recording
server-name
netstream
wiktionary
background-repeat
mvcrecaptcha
dynamic-c
filelock
cewolf
formal-semantics
chunking
ixmldomdocument
asdoc
subtext
levels
code-camp
parentid

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App