<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Why ORM Transactions are Crucial</title>
	<atom:link href="http://www.barneyb.com/barneyblog/2010/04/07/why-orm-transactions-are-crucial/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.barneyb.com/barneyblog/2010/04/07/why-orm-transactions-are-crucial/</link>
	<description>Thoughts, rants, and even some code from the mind of Barney Boisvert.</description>
	<lastBuildDate>Thu, 11 Sep 2014 09:58:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Johan</title>
		<link>https://www.barneyb.com/barneyblog/2010/04/07/why-orm-transactions-are-crucial/comment-page-1/#comment-215736</link>
		<dc:creator>Johan</dc:creator>
		<pubDate>Tue, 13 Jul 2010 02:40:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1453#comment-215736</guid>
		<description>Thanks</description>
		<content:encoded><![CDATA[<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2010/04/07/why-orm-transactions-are-crucial/comment-page-1/#comment-215730</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Mon, 12 Jul 2010 23:18:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1453#comment-215730</guid>
		<description>Johan,

I really have no idea, but my suspicion is that because Derby is an in-JVM DB, it somehow ties together the JVM thread and the DB connection.  When you start doing multithreaded stuff that one-to-one association is no longer valid, and things go south.  That&#039;s pure supposition, however, and quite likely is actually an issue with the CFML engine not using ThreadGroups correctly rather than with Derby.</description>
		<content:encoded><![CDATA[<p>Johan,</p>
<p>I really have no idea, but my suspicion is that because Derby is an in-JVM DB, it somehow ties together the JVM thread and the DB connection.  When you start doing multithreaded stuff that one-to-one association is no longer valid, and things go south.  That's pure supposition, however, and quite likely is actually an issue with the CFML engine not using ThreadGroups correctly rather than with Derby.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Johan</title>
		<link>https://www.barneyb.com/barneyblog/2010/04/07/why-orm-transactions-are-crucial/comment-page-1/#comment-215729</link>
		<dc:creator>Johan</dc:creator>
		<pubDate>Mon, 12 Jul 2010 23:09:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1453#comment-215729</guid>
		<description>@Barney - just out of interest - I use ormGetSession().beginTransaction() as you recommend and it works fine on MySQL and Derby (embedded CF version used for quick tests).

However if I use thread.txn = ormGetSession().beginTransaction() where a separate thread is used to processes data in the background it works fine in MySQL by Derby cannot handle any requests until the thread processing is complete. It gives error like this: java.sql.SQLTransactionRollbackException: A lock could not be obtained within the time requested.

Its not a problem for my apps - just curious why Derby chokes.</description>
		<content:encoded><![CDATA[<p>@Barney &#8211; just out of interest &#8211; I use ormGetSession().beginTransaction() as you recommend and it works fine on MySQL and Derby (embedded CF version used for quick tests).</p>
<p>However if I use thread.txn = ormGetSession().beginTransaction() where a separate thread is used to processes data in the background it works fine in MySQL by Derby cannot handle any requests until the thread processing is complete. It gives error like this: java.sql.SQLTransactionRollbackException: A lock could not be obtained within the time requested.</p>
<p>Its not a problem for my apps &#8211; just curious why Derby chokes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Johan</title>
		<link>https://www.barneyb.com/barneyblog/2010/04/07/why-orm-transactions-are-crucial/comment-page-1/#comment-214692</link>
		<dc:creator>Johan</dc:creator>
		<pubDate>Sun, 27 Jun 2010 19:19:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1453#comment-214692</guid>
		<description>Thanks for clarifying.</description>
		<content:encoded><![CDATA[<p>Thanks for clarifying.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2010/04/07/why-orm-transactions-are-crucial/comment-page-1/#comment-214687</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Sun, 27 Jun 2010 17:40:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1453#comment-214687</guid>
		<description>Johan,

The initial CF9 release is broken regarding the way sessions are handled across transaction boundaries.  The issue has been resolved by the CF team at Adobe.  I would imagine a change of this magnitude would NOT come out as part of a hotfix, but only as a point release, so I&#039;d be surprised if we see it before the official 9.0.1 drop.  I have no information about when that might be.</description>
		<content:encoded><![CDATA[<p>Johan,</p>
<p>The initial CF9 release is broken regarding the way sessions are handled across transaction boundaries.  The issue has been resolved by the CF team at Adobe.  I would imagine a change of this magnitude would NOT come out as part of a hotfix, but only as a point release, so I'd be surprised if we see it before the official 9.0.1 drop.  I have no information about when that might be.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Johan</title>
		<link>https://www.barneyb.com/barneyblog/2010/04/07/why-orm-transactions-are-crucial/comment-page-1/#comment-214503</link>
		<dc:creator>Johan</dc:creator>
		<pubDate>Fri, 25 Jun 2010 21:40:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1453#comment-214503</guid>
		<description>Great post Barney - very good to know. Can you clarify what you mean by &quot;Adobe has fixed the issue, but the initial CF9 bits are broken. &quot; ?

Does that mean in CF9 with latest HotFix/update (or next HF) we can use the CF transaction function and not ormGetSession().beginTransaction()  or is it fixed in a yet to be released HF/update? 

Thanks</description>
		<content:encoded><![CDATA[<p>Great post Barney &#8211; very good to know. Can you clarify what you mean by "Adobe has fixed the issue, but the initial CF9 bits are broken. " ?</p>
<p>Does that mean in CF9 with latest HotFix/update (or next HF) we can use the CF transaction function and not ormGetSession().beginTransaction()  or is it fixed in a yet to be released HF/update? </p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Whish</title>
		<link>https://www.barneyb.com/barneyblog/2010/04/07/why-orm-transactions-are-crucial/comment-page-1/#comment-213521</link>
		<dc:creator>John Whish</dc:creator>
		<pubDate>Thu, 10 Jun 2010 12:50:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1453#comment-213521</guid>
		<description>Thanks Barney - I hadn&#039;t even considered lazy loading. That&#039;s a really good point!</description>
		<content:encoded><![CDATA[<p>Thanks Barney &#8211; I hadn't even considered lazy loading. That's a really good point!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2010/04/07/why-orm-transactions-are-crucial/comment-page-1/#comment-213383</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Mon, 07 Jun 2010 17:03:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1453#comment-213383</guid>
		<description>John,

It depends.  In this simple example it&#039;ll be safe, because creating the new object and calling the setters doesn&#039;t require any DB interaction (which would happen outside a transaction).  The point is that you have your transaction demarcation in the right spot, just as if you were writing SQL manually.  You never do this (read outside a transaction in order to write inside a transaction) with SQL:

&lt;pre&gt;set @x = (select ... from somehwhere ...)
begin transaction
update something set col = @x
commit transaction
&lt;/pre&gt;

The same principle applies with ORM, just it&#039;s far more difficult to determine when the data access is happening when you&#039;re not in control of the raw SQL.  Typically this sort of thing would crop up with defining relationships, but could also be caused by lazy loading across a multi-table entity, certain primary key generators, etc.</description>
		<content:encoded><![CDATA[<p>John,</p>
<p>It depends.  In this simple example it'll be safe, because creating the new object and calling the setters doesn't require any DB interaction (which would happen outside a transaction).  The point is that you have your transaction demarcation in the right spot, just as if you were writing SQL manually.  You never do this (read outside a transaction in order to write inside a transaction) with SQL:</p>
<pre>set @x = (select ... from somehwhere ...)
begin transaction
update something set col = @x
commit transaction
</pre>
<p>The same principle applies with ORM, just it's far more difficult to determine when the data access is happening when you're not in control of the raw SQL.  Typically this sort of thing would crop up with defining relationships, but could also be caused by lazy loading across a multi-table entity, certain primary key generators, etc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Whish</title>
		<link>https://www.barneyb.com/barneyblog/2010/04/07/why-orm-transactions-are-crucial/comment-page-1/#comment-213367</link>
		<dc:creator>John Whish</dc:creator>
		<pubDate>Mon, 07 Jun 2010 10:14:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1453#comment-213367</guid>
		<description>Sorry if this is a dense question Barney, but can I do something like this (with flushatrequestend = false):

&lt;pre&gt;a = new com.site.Account();
a.setName(attributes.name);
a.setUsername(attributes.username);
a.setPassword(attributes.password);

txn = ormGetSession().beginTransaction();
try {
  entitySave(a);
  txn.commit();
} catch (e) {
  txn.rollback();
  throw e;
}
&lt;/pre&gt;

If this is valid then it makes life a lot easier! 

Thanks!

- John</description>
		<content:encoded><![CDATA[<p>Sorry if this is a dense question Barney, but can I do something like this (with flushatrequestend = false):</p>
<pre>a = new com.site.Account();
a.setName(attributes.name);
a.setUsername(attributes.username);
a.setPassword(attributes.password);

txn = ormGetSession().beginTransaction();
try {
  entitySave(a);
  txn.commit();
} catch (e) {
  txn.rollback();
  throw e;
}
</pre>
<p>If this is valid then it makes life a lot easier! </p>
<p>Thanks!</p>
<p>- John</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2010/04/07/why-orm-transactions-are-crucial/comment-page-1/#comment-210218</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Wed, 14 Apr 2010 05:31:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1453#comment-210218</guid>
		<description>Jamie,

If you&#039;re using raw Hibernate, the read-only transaction is a fantastic tool for ensuring you don&#039;t shoot yourself in the foot (and that no one else does either).   Unfortunately it&#039;s not available to us in CF, at least that I&#039;m aware of.

It&#039;s not really about minimizing damage, though.  At least in my mind, it&#039;s more about failing fast when you create a bug (in this case a non-transactional write).  I don&#039;t want to protect my database when it happens in production, I want to ensure that the developer gets yelled at when it happens in development so the broken code won&#039;t ever make it to SVN.  Which isn&#039;t to say the in-production benefits aren&#039;t nice (they&#039;re hella nice), but a hard fail at develop time is a huge win.</description>
		<content:encoded><![CDATA[<p>Jamie,</p>
<p>If you're using raw Hibernate, the read-only transaction is a fantastic tool for ensuring you don't shoot yourself in the foot (and that no one else does either).   Unfortunately it's not available to us in CF, at least that I'm aware of.</p>
<p>It's not really about minimizing damage, though.  At least in my mind, it's more about failing fast when you create a bug (in this case a non-transactional write).  I don't want to protect my database when it happens in production, I want to ensure that the developer gets yelled at when it happens in development so the broken code won't ever make it to SVN.  Which isn't to say the in-production benefits aren't nice (they're hella nice), but a hard fail at develop time is a huge win.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
