karaf-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Soto <alex.s...@envieta.com>
Subject Re: MariaDB/JPA Transaction rollback not working
Date Thu, 17 May 2018 16:26:36 GMT
<html><head></head><body dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode:
space; line-break: after-white-space;"><meta http-equiv="Content-Type" content="text/html;
charset=utf-8"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break:
after-white-space;" class="">Allright, &nbsp;I am trying to follow the EnRoute tutorial.<div
class=""><br class=""></div><div class="">I am getting this error:</div><div
class=""><br class=""></div><div class="">[ERROR] Plugin biz.aQute.bnd:bnd-maven-plugin:4.0.0-SNAPSHOT
or one of its dependencies could not be&nbsp;resolved: Could not find artifact biz.aQute.bnd:bnd-maven-plugin:jar:4.0.0-SNAPSHOT
in Bnd Snapshots&nbsp;(<a href="https://bndtools.ci.cloudbees.com/job/bnd.master/lastSuccessfulBuild/artifact/dist/bundles/"
class="">https://bndtools.ci.cloudbees.com/job/bnd.master/lastSuccessfulBuild/artifact/dist/bundles/</a>)
-&gt; [Help 1]</div><div class=""><br class=""></div><div class=""><br
class=""></div><div class="">Any idea (time frame) when this will move from
SNAPSHOT dependencies?</div><div class=""><br class=""></div><div
class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width:
0px; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Best
regards,<br class="">Alex soto<br class=""><br class=""><br class=""><br
class=""></div>
</div>
<div><br class=""><blockquote type="cite" class=""><div class="">On
May 17, 2018, at 11:08 AM, Tim Ward &lt;<a href="mailto:tim.ward@paremus.com" class="">tim.ward@paremus.com</a>&gt;
wrote:</div><br class="Apple-interchange-newline"><div class=""><meta
http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto"
class="">It is highly unlikely that you’ll hit the same issues. The transaction control
resource provider uses the DataSourceFactory directly to create a DataSource (either progamatically
using a factory service or via config admin) that enlists itself in the ongoing transaction.
This means that the answer to your question is “with Transaction Control you don’t have
to do that because it does it automatically”<div class=""><br class=""></div><div
class="">If you want to use XA transactions then the only requirement is that the DataSourceFactory
can produce an XADataSource, otherwise it just uses the standard JDBC API to commit/rollback.
If your DataSourceFactory doesn’t support XA then use the local resource provider implementation.</div><div
class=""><br class=""></div><div class="">Best Regards,</div><div
class=""><br class=""></div><div class="">Tim</div><div class=""><br
class=""><div class="">Sent from my iPhone</div><div class=""><br
class="">On 17 May 2018, at 15:17, Alex Soto &lt;<a href="mailto:alex.soto@envieta.com"
class="">alex.soto@envieta.com</a>&gt; wrote:<br class=""><br class=""></div><blockquote
type="cite" class=""><div class=""><meta http-equiv="Content-Type" content="text/html;
charset=utf-8" class="">I will take a look at these examples.<div class=""><br
class=""></div><div class="">However, I think that if I cannot get a MariaDB
DataSource that supports transactions, then it will still not work, right?</div><div
class="">If the examples use H2 database, I still may get different results when I change
to MariaDB, and I will find myself in the same spot as of now.</div><div class=""><br
class=""></div><div class="">So, the question remains about what is the correct
way how to register a transaction aware MariaDB DataSource.</div><div class=""><div
class=""><br class=""></div><div class=""><br class=""></div><div
class=""><div class="">
<div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform:
none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word;
-webkit-nbsp-mode: space; line-break: after-white-space;" class="">Best regards,<br
class="">Alex soto<br class=""><br class=""><br class=""><br class=""></div>
</div>
<div class=""><br class=""><blockquote type="cite" class=""><div class="">On
May 17, 2018, at 1:46 AM, Tim Ward &lt;<a href="mailto:tim.ward@paremus.com" class="">tim.ward@paremus.com</a>&gt;
wrote:</div><br class="Apple-interchange-newline"><div class=""><meta
http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto"
class="">The best place to start when looking for OSGi R7 examples is the enRoute Project.
It contains Maven Archetypes, examples and worked tutorials for building applications using
R7 specifications.&nbsp;<div class=""><br class=""></div><div class=""><a
href="https://enroute.osgi.org/Tutorial/" class="">https://enroute.osgi.org</a></div><div
class=""><br class=""></div><div class="">Most of the projects in use
are just new versions of long established OSGi implementations from Aries and Felix. The majority
of them are already released and in Maven Central. Those that are still in the process of
releasing (pretty much just the JAX-RS whiteboard) are available in the Apache Snapshots repository.
I am not aware of any implementations that require R7 framework features, so all of them should
run on Karaf.</div><div class=""><br class=""></div><div class="">Best
Regards,</div><div class=""><br class=""></div><div class="">Tim<br
class=""><br class=""><div class="">Sent from my iPhone</div><div
class=""><br class="">On 16 May 2018, at 22:25, Alex Soto &lt;<a href="mailto:alex.soto@envieta.com"
class="">alex.soto@envieta.com</a>&gt; wrote:<br class=""><br class=""></div><blockquote
type="cite" class=""><div class=""><meta http-equiv="Content-Type" content="text/html;
charset=utf-8" class="">I agree, it s very frustrating and time consuming. Almost impossible
to get it right.<div class="">I may try the OSGi R7, but I am not sure of its adoption
level at this time, availability of bundles, examples, support by Karaf, etc.</div><div
class=""><br class=""><div class=""><br class=""></div><div
class="">Anyway, back to my current stack. &nbsp;I only see one DataSource being registered:</div><div
class=""><br class=""></div><div class=""><font face="Courier" class="">karaf@root()&gt;&nbsp;service:list&nbsp;DataSource<br
class="">[javax.sql.DataSource]<br class="">----------------------<br class="">&nbsp;databaseName
= responder<br class="">&nbsp;dataSourceName = responder<br class="">&nbsp;osgi.jdbc.driver.name
= mariadb<br class="">&nbsp;osgi.jndi.service.name = responder<br class="">&nbsp;service.bundleid
= 14<br class="">&nbsp;service.factoryPid = org.ops4j.datasource<br class="">&nbsp;<a
href="http://service.id/" class="">service.id</a> = 194<br class="">&nbsp;service.pid
= org.ops4j.datasource.feb33f6d-dc46-4bc7-a417-ad6bdd5a6ee5<br class="">&nbsp;service.scope
= singleton<br class="">&nbsp;url = jdbc:mariadb:XXXXXX<br class="">Provided
by :&nbsp;<br class="">&nbsp;OPS4J Pax JDBC Config (14)<br class="">Used
by:&nbsp;<br class="">&nbsp;Data (135)</font></div><div class=""><br
class=""></div><div class=""><br class=""></div><div class=""><div
class="">Not sure what to do with this. &nbsp;</div><div class="">I specified
the following in the configuration:</div><div class=""><br class=""></div><div
class=""><div style="margin: 0px; font-stretch: normal; font-size: 19px; line-height:
normal; font-family: Inconsolata; color: rgb(57, 51, 255);" class=""><span style=""
class="">pool=</span><span style="text-decoration: underline" class="">narayana</span></div><div
style="margin: 0px; font-stretch: normal; font-size: 19px; line-height: normal; font-family:
Inconsolata; color: rgb(57, 51, 255);" class=""><span style="" class="">xa=</span>true</div></div><div
class=""><br class=""><div class="">
<div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform:
none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word;
-webkit-nbsp-mode: space; line-break: after-white-space;" class="">Best regards,<br
class="">Alex soto<br class=""><br class=""><br class=""><br class=""></div>
</div>
<div class=""><br class=""><blockquote type="cite" class=""><div class="">On
May 16, 2018, at 4:12 PM, Tim Ward &lt;<a href="mailto:tim.ward@paremus.com" class="">tim.ward@paremus.com</a>&gt;
wrote:</div><br class="Apple-interchange-newline"><div class=""><meta
http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto"
class="">The structure of the JNDI name is defined by the JNDI service specification.&nbsp;<div
class=""><br class=""></div><div class="">osgi:service/&lt;interface
name&gt;[/&lt;filter&gt;]</div><div class=""><br class=""></div><div
class="">So in this case both of your services should be DataSource instances, but they
should have different filters.&nbsp;</div><div class=""><br class=""></div><div
class="">The important thing is to make sure you have an JTA enlisting DataSource registered
as a service (this isn’t just your normal DataSource), then to build a filter which selects
that. One option for this is to use the enlistment whiteboard from Aries (not well documented)&nbsp;<a
href="https://github.com/apache/aries/tree/trunk/transaction/transaction-jdbc" class="">https://github.com/apache/aries/tree/trunk/transaction/transaction-jdbc</a></div><div
class=""><br class=""></div><div class="">This is a non-trivial thing
to do, which is why I keep mentioning Transaction Control which handles the enlistment reliably
without the layers of services.&nbsp;</div><div class=""><br class=""></div><div
class="">Best Regards,</div><div class=""><br class=""></div><div
class="">Tim</div><div class=""><br class=""><div class="">Sent
from my iPhone</div><div class=""><br class="">On 16 May 2018, at 21:57,
Alex Soto &lt;<a href="mailto:alex.soto@envieta.com" class="">alex.soto@envieta.com</a>&gt;
wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div
class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class="">Thank
you Tim.<div class=""><br class=""></div><div class="">Any idea what
the JNDI names would be?<div class="">It is Pax-JDBC creating these JNDI names, so I
have no idea.</div><div class=""><br class=""></div><div class="">From
the Karaf console:</div><div class=""><br class=""></div><div class=""><br
class=""></div><div class=""><font face="Courier" class="">karaf@root()&gt;&nbsp;jndi:names&nbsp;<br
class="">JNDI Name&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;│
Class Name<br class="">───────────────────────┼───────────────────────────────────────────────<br
class="">osgi:service/responder │ org.mariadb.jdbc.MySQLDataSource<br class="">osgi:service/jndi&nbsp;
&nbsp; &nbsp;&nbsp;│ org.apache.karaf.jndi.internal.JndiServiceImpl<br class=""><br
class=""></font></div><div class=""><br class=""><div class="">
<div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform:
none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word;
-webkit-nbsp-mode: space; line-break: after-white-space;" class="">Best regards,<br
class="">Alex soto<br class=""><br class=""><br class=""><br class=""></div>
</div>
<div class=""><br class=""><blockquote type="cite" class=""><div class="">On
May 16, 2018, at 3:48 PM, Tim Ward &lt;<a href="mailto:tim.ward@paremus.com" class="">tim.ward@paremus.com</a>&gt;
wrote:</div><br class="Apple-interchange-newline"><div class=""><div
class="">Just looking quickly. <br class=""><br class="">You have the same
JNDI name for both JTA and non JTA DataSources. This is clearly wrong as the DataSource cannot
simultaneously be enlisted in the Transaction and not enlisted. The comments also indicate
a misunderstanding of the purpose of the non-jta-datasource, which absolutely is used with
JTA EntityManagers (for things like sequence allocation and out of band optimisations). You
really do need to have both and they do need to behave differently.<br class=""><br
class="">At a guess your DataSource is not enlisted with the transaction manager present
in the system. &nbsp;This usually happens by configuring a (otherwise invisible) DataSource
wrapper There is nothing forcing you to make this happen (or checking that it does) hence
your transactions would be broken. This is one of the several reasons I try to direct people
to Transaction Control where the model actively pushes you toward transactions that actually
work, rather than hiding all the magic behind an annotation.<br class=""><br class="">Hopefully
this gives you some clues as to what might be wrong. <br class=""><br class="">Best
Regards,<br class=""><br class="">Tim<br class=""><br class="">Sent
from my iPhone<br class=""><br class=""><blockquote type="cite" class="">On
16 May 2018, at 21:34, Jean-Baptiste Onofré &lt;<a href="mailto:jb@nanthrax.net" class="">jb@nanthrax.net</a>&gt;
wrote:<br class=""><br class="">Are you sure about your code ? Flush looks weird
to me and it seems you don't use container managed transaction.<br class=""><br class="">Regards<br
class="">JB<br class=""><br class=""><blockquote type="cite" class="">On
16/05/2018 21:08, Alex Soto wrote:<br class="">Yes, same result. &nbsp;I even tried
with Narayana Transaction Manager, and same result.<br class="">Best regards,<br
class="">Alex soto<br class=""><blockquote type="cite" class="">On May 16,
2018, at 2:56 PM, Jean-Baptiste Onofré &lt;<a href="mailto:jb@nanthrax.net" class="">jb@nanthrax.net</a>
&lt;<a href="mailto:jb@nanthrax.net" class="">mailto:jb@nanthrax.net</a>&gt;&gt;
wrote:<br class=""><br class="">Same behavior with RequiresNew ?<br class=""><br
class="">Regards<br class="">JB<br class=""><br class=""><blockquote
type="cite" class="">On 16/05/2018 19:44, Alex Soto wrote:<br class="">With Karaf
version 4.2.0, Rollback is not working with MariaDB and InnoDB tables.<br class="">I
deployed these features (from Karaf’s enterprise &nbsp;repository):<br class="">&lt;feature&gt;aries-blueprint&lt;/feature&gt;<br
class="">&lt;feature&gt;transaction&lt;/feature&gt;<br class="">&lt;feature&gt;jndi&lt;/feature&gt;<br
class="">&lt;feature&gt;jdbc&lt;/feature&gt;<br class="">&lt;feature&gt;jpa&lt;/feature&gt;<br
class="">&lt;feature&gt;pax-jdbc-mariadb&lt;/feature&gt;<br class="">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;feature&gt;pax-jdbc-config&lt;/feature&gt;<br
class="">&lt;feature&gt;pax-jdbc-pool-dbcp2&lt;/feature&gt;<br class="">&lt;feature&gt;hibernate&lt;/feature&gt;<br
class="">My Data Source is configured in the file /org.ops4j.datasource-responder.cfg/<br
class=""> &nbsp;&nbsp;osgi.jdbc.driver.name = mariadb<br class=""> &nbsp;&nbsp;dataSourceName=responder<br
class=""> &nbsp;&nbsp;url<br class=""> &nbsp;&nbsp;= jdbc:<a href="mariadb://mariadb.local:3306/responder?characterEncoding=UTF-8&amp;useServerPrepStmts=true&amp;autocommit=false"
class="">mariadb://mariadb.local:3306/responder?characterEncoding=UTF-8&amp;useServerPrepStmts=true&amp;autocommit=false</a><br
class=""> &nbsp;&nbsp;user=XXXX<br class=""> &nbsp;&nbsp;password=XXXX<br
class=""> &nbsp;&nbsp;databaseName=responder<br class=""> &nbsp;&nbsp;#Pool
Config<br class=""> &nbsp;&nbsp;pool=dbcp2<br class=""> &nbsp;&nbsp;xa=true<br
class="">My persistence.xml:<br class=""> &nbsp;&nbsp;&lt;persistence
version="2.0" xmlns="<a href="http://java.sun.com/xml/ns/persistence" class="">http://java.sun.com/xml/ns/persistence</a>"<br
class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:xsi="<a
href="http://www.w3.org/2001/XMLSchema-instance" class="">http://www.w3.org/2001/XMLSchema-instance</a>"<br
class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xsi:schemaLocation="<a
href="http://java.sun.com/xml/ns/persistence" class="">http://java.sun.com/xml/ns/persistence</a><br
class=""><a href="http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" class="">http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd</a>"&gt;<br
class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;persistence-unit
name="responderPersistenUnit" transaction-type="JTA"&gt;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;<br
class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--
Only used when transaction-type=JTA --&gt;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;jta-data-source&gt;osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=responder)&lt;/jta-data-source&gt;<br
class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--
Only used when transaction-type=RESOURCE_LOCAL --&gt;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;non-jta-data-source&gt;osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=responder)&lt;/non-jta-data-source&gt;<br
class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;properties&gt;<br
class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;property
name=“hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" /&gt;<br class="">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;property
name="hibernate.show_sql" value="true" /&gt;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;property
name="hibernate.format_sql" value="true" /&gt;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;property
name="hibernate.hbm2ddl.auto" value="none"/&gt;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/properties&gt;<br
class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/persistence-unit&gt;<br
class=""> &nbsp;&nbsp;&lt;/persistence&gt;<br class="">My blueprint.xml:<br
class=""> &nbsp;&nbsp;&lt;blueprint xmlns="<a href="http://www.osgi.org/xmlns/blueprint/v1.0.0"
class="">http://www.osgi.org/xmlns/blueprint/v1.0.0</a>"<br class=""> &nbsp;&nbsp;xmlns:jpa="<a
href="http://aries.apache.org/xmlns/jpa/v2.0.0" class="">http://aries.apache.org/xmlns/jpa/v2.0.0</a>"<br
class=""> &nbsp;&nbsp;xmlns:tx="<a href="http://aries.apache.org/xmlns/transactions/v2.0.0"
class="">http://aries.apache.org/xmlns/transactions/v2.0.0</a>"<br class="">
&nbsp;&nbsp;xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" class="">http://www.w3.org/2001/XMLSchema-instance</a>"<br
class=""> &nbsp;&nbsp;xsi:schemaLocation="<a href="http://www.osgi.org/xmlns/blueprint/v1.0.0"
class="">http://www.osgi.org/xmlns/blueprint/v1.0.0</a><br class=""><a href="https://osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"
class="">https://osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd</a>"&gt;<br
class=""> &nbsp;&nbsp;&lt;jpa:enable /&gt;<br class=""> &nbsp;&nbsp;&lt;tx:enable
/&gt;<br class=""> &nbsp;&nbsp;&lt;bean id="userService" class="org.data.impl.UserServiceImpl"
/&gt;<br class=""> &nbsp;&nbsp;&lt;service ref="userService" interface="org.data.UserService"
/&gt;<br class=""> &nbsp;&nbsp;&lt;/blueprint&gt;<br class="">For
testing I throw exception in my DAO:<br class="">@Transactional(REQUIRED)<br class="">public
void addUser(User user) {<br class="">em.persist(user);<br class="">em.flush();<br
class="">throw new RuntimeException("On Purpose");<br class="">}<br class="">I
expect the record not to be in the table due to rollback of the transaction, but it still
shows up in my database table.<br class="">Best regards,<br class="">Alex soto<br
class=""></blockquote></blockquote></blockquote></blockquote></div></div></blockquote></div><br
class=""></div></div></div></blockquote></div></div></div></blockquote></div><br
class=""></div></div></div></div></blockquote></div></div></div></blockquote></div><br
class=""></div></div></div></blockquote></div></div></div></blockquote></div><br
class=""></div></div></body></html>
Mime
View raw message