You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by rizal123 <kh...@btpn.com> on 2018/01/26 09:24:10 UTC
No transaction is currently active || Not allowed to create
transaction on shared EntityManager - use Spring transactions or EJB CMT
instead
Hi,
First of all, yes I know Apache Ignite not support SQL Transaction. I hope
this is not showstopper of my POC.
I`m here to find another way.
1. I have function for update sequence table.
private int sequenceManual(String seqName) {
int seq = 0;
Query query;
try {
query = this.em.createNativeQuery("UPDATE SEQUENCE SET SEQ_COUNT =
SEQ_COUNT + " + INCREMENT + " WHERE SEQ_NAME = '" +seqName+"'");
seq = (Integer) query.executeUpdate();
} catch (Exception e) {
LOG.error("An exception was thrown while Update Sequence " + seqName, e);
}
try {
query = this.em.createNativeQuery("SELECT SEQ_COUNT FROM SEQUENCE WHERE
SEQ_NAME = '"+ seqName +"'");
seq = (int) ((Number) query.getSingleResult()).longValue();
} catch (Exception e) {
LOG.error("An exception was thrown while Next Return Sequence " + seqName,
e);
}
return seq;
}
with this code, I have an error:
javax.persistence.TransactionRequiredException: Exception Description: No
transaction is currently active
Then, I modified my code with @Transactional Spring.
@Transactional(propagation=Propagation.REQUIRED)
private int sequenceManual(String seqName) {
. . . .
I have an error:
java.lang.IllegalStateException: Not allowed to create transaction on shared
EntityManager - use Spring transactions or EJB CMT instead
Is there something suggestion to running my Update Sequence SQL?
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: No transaction is currently active || Not allowed to create
transaction on shared EntityManager - use Spring transactions or EJB CMT
instead
Posted by rizal123 <kh...@btpn.com>.
Hi Evgenii ,
Yes i have try that. Without Spring Transaction.
private int sequenceManual(String seqName) {
int seq = 0;
Query query;
try {
em.getTransaction().begin();
query = this.em.createNativeQuery("UPDATE SEQUENCE SET SEQ_COUNT =
SEQ_COUNT + " + INCREMENT + " WHERE SEQ_NAME = '" +seqName+"'");
seq = (Integer) query.executeUpdate();
em.getTransaction().commit();
And also get an error:
java.lang.IllegalStateException: Not allowed to create transaction on shared
EntityManager - use Spring transactions or EJB CMT instead
Would you share your code here Evgenii ?
Thanks for your help...
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: No transaction is currently active || Not allowed to create
transaction on shared EntityManager - use Spring transactions or EJB CMT instead
Posted by Evgenii Zhuravlev <e....@gmail.com>.
Unfortunately, there is more than one file and it will look unreadable
here. All code can be accessed on github via the link I've provided earlier.
Evgenii
2018-01-30 7:10 GMT+03:00 Amir Akhmedov <am...@gmail.com>:
> You need to register a bean as follow
>
> <bean id="transactionManager" class="org.apache.ignite.transactions.spring.SpringTransactionManager">
> <property name="transactionConcurrency" value="OPTIMISTIC"/>
> <property name="igniteInstanceName" value="testGrid"/>
> </bean>
>
>
> Please check the link a sent you earlier it has tests with all required configurations. It can serve as a good example.
>
>
Re: No transaction is currently active || Not allowed to create
transaction on shared EntityManager - use Spring transactions or EJB CMT instead
Posted by Amir Akhmedov <am...@gmail.com>.
You need to register a bean as follow
<bean id="transactionManager"
class="org.apache.ignite.transactions.spring.SpringTransactionManager">
<property name="transactionConcurrency" value="OPTIMISTIC"/>
<property name="igniteInstanceName" value="testGrid"/>
</bean>
Please check the link a sent you earlier it has tests with all
required configurations. It can serve as a good example.
Re: No transaction is currently active || Not allowed to create
transaction on shared EntityManager - use Spring transactions or EJB CMT
instead
Posted by rizal123 <kh...@btpn.com>.
Hi Amir,
How to registered Ignite's Spring Transaction Manager?
Would you mind share your code...
Thanks for your help Amir....
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: No transaction is currently active || Not allowed to create
transaction on shared EntityManager - use Spring transactions or EJB CMT instead
Posted by Amir Akhmedov <am...@gmail.com>.
Also, please make sure you registered Ignite's Spring Transaction Manager.
As an example for Ignite and Spring Transaction you can check
https://github.com/apache/ignite/tree/master/modules/spring/src/test/java/org/apache/ignite/transactions/spring
Thanks,
Amir
On Mon, Jan 29, 2018 at 9:38 AM, ezhuravlev <e....@gmail.com>
wrote:
> Hi,
>
> I think now you need to start and commit transaction manually in your code:
> em.getTransaction().begin();
> em.getTransaction().commit();
>
> At least I've tried it some time ago and it worked. Please check this
> example on github:
> https://github.com/ezhuravl/ignite-eclipselink-example
>
> Evgenii
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>
--
Sincerely Yours Amir Akhmedov
Re: No transaction is currently active || Not allowed to create
transaction on shared EntityManager - use Spring transactions or EJB CMT
instead
Posted by ezhuravlev <e....@gmail.com>.
Hi,
I think now you need to start and commit transaction manually in your code:
em.getTransaction().begin();
em.getTransaction().commit();
At least I've tried it some time ago and it worked. Please check this
example on github:
https://github.com/ezhuravl/ignite-eclipselink-example
Evgenii
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/