<?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"
	>
<channel>
	<title>Comments on: Hibernate Pitfalls part 3</title>
	<atom:link href="http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/feed/" rel="self" type="application/rss+xml" />
	<link>http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/</link>
	<description>Brian Pontarelli</description>
	<pubDate>Tue, 06 Jan 2009 21:49:09 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Sticky Bandit</title>
		<link>http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-33038</link>
		<dc:creator>Sticky Bandit</dc:creator>
		<pubDate>Thu, 02 Oct 2008 15:49:51 +0000</pubDate>
		<guid isPermaLink="false">http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-33038</guid>
		<description>Why anyone would use Hibernate for any project just shows that they don't know anything about software system design.  What do I gain from using Hibernate?  Nothing but a mess!  You will find that hibernate lovers don't really understand the power of a hash map or a result set.  Bulk data is easy.  Ask them if they would return 10 books back to the library one trip at a time in their car-book delivery object, DAO or whatever.  I why are we writing SQL on top of objects?  SQL is for Relational Databases.  If I do have objects, the last thing I want to do is go back to SQL again.  I just have to shake my head at the trends people follow.  :&#124;</description>
		<content:encoded><![CDATA[<p>Why anyone would use Hibernate for any project just shows that they don&#8217;t know anything about software system design.  What do I gain from using Hibernate?  Nothing but a mess!  You will find that hibernate lovers don&#8217;t really understand the power of a hash map or a result set.  Bulk data is easy.  Ask them if they would return 10 books back to the library one trip at a time in their car-book delivery object, DAO or whatever.  I why are we writing SQL on top of objects?  SQL is for Relational Databases.  If I do have objects, the last thing I want to do is go back to SQL again.  I just have to shake my head at the trends people follow.  :|</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles</title>
		<link>http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-10597</link>
		<dc:creator>Charles</dc:creator>
		<pubDate>Thu, 27 Mar 2008 20:03:43 +0000</pubDate>
		<guid isPermaLink="false">http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-10597</guid>
		<description>+1 to Brian for keeping a level, constructive, and informative discussion going.  Always better to attack the issues than the person.  So refreshing in cyberspace...</description>
		<content:encoded><![CDATA[<p>+1 to Brian for keeping a level, constructive, and informative discussion going.  Always better to attack the issues than the person.  So refreshing in cyberspace&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: aninymous</title>
		<link>http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-7780</link>
		<dc:creator>aninymous</dc:creator>
		<pubDate>Fri, 01 Feb 2008 06:49:04 +0000</pubDate>
		<guid isPermaLink="false">http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-7780</guid>
		<description>I dislike hibernate and I don't think it eases development. Developers may not need to consider writing the SQL (how hard it could be?) but they are the same time limited by hibernate 'rules'. Hibernate just has too many tricks. And it almost always creates unnecessary database queries:

Suppose we have two classes, Person and Address, and they have nbi-directional one-to-many relationship (one person having multiple addresses). Hibernate says we use the following to add a new address to a person:

Session session = ...;

Address newAddress = new Address();
Person person = session.get(...);
person.getAddresses().add(newAddress);  //</description>
		<content:encoded><![CDATA[<p>I dislike hibernate and I don&#8217;t think it eases development. Developers may not need to consider writing the SQL (how hard it could be?) but they are the same time limited by hibernate &#8216;rules&#8217;. Hibernate just has too many tricks. And it almost always creates unnecessary database queries:</p>
<p>Suppose we have two classes, Person and Address, and they have nbi-directional one-to-many relationship (one person having multiple addresses). Hibernate says we use the following to add a new address to a person:</p>
<p>Session session = &#8230;;</p>
<p>Address newAddress = new Address();<br />
Person person = session.get(&#8230;);<br />
person.getAddresses().add(newAddress);  //</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Francois</title>
		<link>http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-5841</link>
		<dc:creator>Francois</dc:creator>
		<pubDate>Fri, 14 Dec 2007 01:00:12 +0000</pubDate>
		<guid isPermaLink="false">http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-5841</guid>
		<description>It's too bad Max gave you such a hard time with your post. There are so many other post about "how woderful hibernate is", there has to be others (like yours) outlining how hibernate can be difficult to offset the inbalance.  

I have used hibernate on 2 large projects, one where we designed the system from the ground up (hince the database was built for the object model) and another where we applied hibernate to a legacy product (thus the database had not object model design behind).  

In the first project, hibernate was a nice as it did all the work for us.  However, in terms of scalability, we hit a wall later once we realized how many queries it makes to keep its cache in sync with the DB.  Hibernate is still there, but we had to find many work around to scale.  Has someone said before on your posts, every framework have weaknesses, and finding them was not cheap for us.

On the second project, we had to throw hibernate out and move to commons.dbutils (something equivalent).  We realized that mapping hibernate to a legacy database structure was difficult and hibernate did not handle it. One can argue that the design of this database was bad, but there are many "bad" design out there and we need to continue maintaning them.  Nevertheless, I was committed to keep hibernate for this project until we reached a point where hibernate was throwing exception for bad code it generated.  No one answered my posting on their site, so I was forced to pull it out.  

Hibernate is a fine tool to get something up and running quickly and easily.  However, for large scale project with high performance requirements, I am doubtful (based on my experience) of its benefits.</description>
		<content:encoded><![CDATA[<p>It&#8217;s too bad Max gave you such a hard time with your post. There are so many other post about &#8220;how woderful hibernate is&#8221;, there has to be others (like yours) outlining how hibernate can be difficult to offset the inbalance.  </p>
<p>I have used hibernate on 2 large projects, one where we designed the system from the ground up (hince the database was built for the object model) and another where we applied hibernate to a legacy product (thus the database had not object model design behind).  </p>
<p>In the first project, hibernate was a nice as it did all the work for us.  However, in terms of scalability, we hit a wall later once we realized how many queries it makes to keep its cache in sync with the DB.  Hibernate is still there, but we had to find many work around to scale.  Has someone said before on your posts, every framework have weaknesses, and finding them was not cheap for us.</p>
<p>On the second project, we had to throw hibernate out and move to commons.dbutils (something equivalent).  We realized that mapping hibernate to a legacy database structure was difficult and hibernate did not handle it. One can argue that the design of this database was bad, but there are many &#8220;bad&#8221; design out there and we need to continue maintaning them.  Nevertheless, I was committed to keep hibernate for this project until we reached a point where hibernate was throwing exception for bad code it generated.  No one answered my posting on their site, so I was forced to pull it out.  </p>
<p>Hibernate is a fine tool to get something up and running quickly and easily.  However, for large scale project with high performance requirements, I am doubtful (based on my experience) of its benefits.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Huang</title>
		<link>http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-5730</link>
		<dc:creator>Mike Huang</dc:creator>
		<pubDate>Mon, 10 Dec 2007 20:07:19 +0000</pubDate>
		<guid isPermaLink="false">http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-5730</guid>
		<description>Why Hibernate or other ORM anyway in first place? The first problem people facing is the performance when a joined query involves multi-tables. Hibernate executes hundreds of selects and painfully slow. commons.dbutils provides the balance between class/table mapping and flexibilities. Any ORM tools just add complexities and numerous pitfalls resulting maintainability nightmare.</description>
		<content:encoded><![CDATA[<p>Why Hibernate or other ORM anyway in first place? The first problem people facing is the performance when a joined query involves multi-tables. Hibernate executes hundreds of selects and painfully slow. commons.dbutils provides the balance between class/table mapping and flexibilities. Any ORM tools just add complexities and numerous pitfalls resulting maintainability nightmare.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Max</title>
		<link>http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-3517</link>
		<dc:creator>Max</dc:creator>
		<pubDate>Sun, 15 Apr 2007 12:09:54 +0000</pubDate>
		<guid isPermaLink="false">http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-3517</guid>
		<description>FYI: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2564</description>
		<content:encoded><![CDATA[<p>FYI: <a href="http://opensource.atlassian.com/projects/hibernate/browse/HHH-2564" rel="nofollow">http://opensource.atlassian.com/projects/hibernate/browse/HHH-2564</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Max</title>
		<link>http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-3515</link>
		<dc:creator>Max</dc:creator>
		<pubDate>Sun, 15 Apr 2007 09:51:13 +0000</pubDate>
		<guid isPermaLink="false">http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-3515</guid>
		<description>A statelesssession operates with a temporary persistencecontext. check the code.

After verifying with some extra tests I see there is cases that is not covered; that needs to be fixed.

"// â€¦ session.createQuery(â€from Order o left join fetch o.detailsâ€); â€¦
Does each â€œorderlineâ€ refer to the same instance of order?"

Currently that will only work if you an " details left join fetch details.order".</description>
		<content:encoded><![CDATA[<p>A statelesssession operates with a temporary persistencecontext. check the code.</p>
<p>After verifying with some extra tests I see there is cases that is not covered; that needs to be fixed.</p>
<p>&#8220;// â€¦ session.createQuery(â€from Order o left join fetch o.detailsâ€); â€¦<br />
Does each â€œorderlineâ€ refer to the same instance of order?&#8221;</p>
<p>Currently that will only work if you an &#8221; details left join fetch details.order&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Bygrave</title>
		<link>http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-3512</link>
		<dc:creator>Rob Bygrave</dc:creator>
		<pubDate>Sun, 15 Apr 2007 00:45:56 +0000</pubDate>
		<guid isPermaLink="false">http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-3512</guid>
		<description>Hmm, not too sure what the -&#62; means. 

According to me (my testing of StatelessSession) and the Hibernate docs StatelessSession operates without ANY first level cache (Aka no persistence context at all).
 
My definition of "Statement level persistence context" is...
A Persistence Context exists and is scoped to a single statement (for the purposes of building a consistent object graph). 

e.g Execute a single query returning orders and order lines - does the object graph contain "data aliasing" (multiple instances that represent the same logical entity).


// ... session.createQuery("from Order o left join fetch o.details"); ...
Does each "orderline" refer to the same instance of order?

With StatelessSession they do not (which is consistent with the doc).  If it used "Statement level persistence context" they would (my definition).

That is, Hibernate StatelessSession states it has no "first level cache" as opposed to "its first level cache is scoped to a single statement". 

Hmm, interesting...</description>
		<content:encoded><![CDATA[<p>Hmm, not too sure what the -&gt; means. </p>
<p>According to me (my testing of StatelessSession) and the Hibernate docs StatelessSession operates without ANY first level cache (Aka no persistence context at all).</p>
<p>My definition of &#8220;Statement level persistence context&#8221; is&#8230;<br />
A Persistence Context exists and is scoped to a single statement (for the purposes of building a consistent object graph). </p>
<p>e.g Execute a single query returning orders and order lines - does the object graph contain &#8220;data aliasing&#8221; (multiple instances that represent the same logical entity).</p>
<p>// &#8230; session.createQuery(&#8221;from Order o left join fetch o.details&#8221;); &#8230;<br />
Does each &#8220;orderline&#8221; refer to the same instance of order?</p>
<p>With StatelessSession they do not (which is consistent with the doc).  If it used &#8220;Statement level persistence context&#8221; they would (my definition).</p>
<p>That is, Hibernate StatelessSession states it has no &#8220;first level cache&#8221; as opposed to &#8220;its first level cache is scoped to a single statement&#8221;. </p>
<p>Hmm, interesting&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Max</title>
		<link>http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-3502</link>
		<dc:creator>Max</dc:creator>
		<pubDate>Fri, 13 Apr 2007 07:01:42 +0000</pubDate>
		<guid isPermaLink="false">http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-3502</guid>
		<description>"Statement level persistence context" -&#62; StatelessSession</description>
		<content:encoded><![CDATA[<p>&#8220;Statement level persistence context&#8221; -&gt; StatelessSession</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Bygrave</title>
		<link>http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-3498</link>
		<dc:creator>Rob Bygrave</dc:creator>
		<pubDate>Thu, 12 Apr 2007 21:59:28 +0000</pubDate>
		<guid isPermaLink="false">http://brian.pontarelli.com/2007/04/06/hibernate-pitfalls-part-3/#comment-3498</guid>
		<description>If its ok, I may take a different approach of looking at this issue.
Hopefully this makes sense :)

Note: I'm relating the 'cache' you refer to as the JPA Persistence Context. 
This can be confusing in the sense that many ORM's have another 'global cache'. 

To start with, the way I view JPA Persistence Context is....

Persistence Context has 2 functions/jobs
- Building 'consistent' object graphs
- in JPA used in flush to persist all 'dirty' persistent objects

Persistence Context has 3 levels
- Statement (my concept, not in JPA)
- Transaction
- Extended (across multiple transactions)

The way I see the issue you describe here Brian is:
Either: You'd like to not have JPA flush dirty objects automatically.
In the example, setName("Bar") means that Bar is used in the update.

Or: You want the query to run with "Statement level persistence context".
In the example the query runs in the same transaction and by default there is
'Transaction Level persistence context'. As the object is already in the persistence
context then the query returns the same instance.

It seems to me that if either of these options where available, they would
resolve the issue you described?

Note: Statement level Persistence Context is NOT mentioned in JPA or
anywhere else (that I know of). Its a concept I use. 

I wrote this document on Persistence Context that may help (hopefully).
http://www.avaje.org/persistencecontext.html

Does any of that make sense?</description>
		<content:encoded><![CDATA[<p>If its ok, I may take a different approach of looking at this issue.<br />
Hopefully this makes sense :)</p>
<p>Note: I&#8217;m relating the &#8216;cache&#8217; you refer to as the JPA Persistence Context.<br />
This can be confusing in the sense that many ORM&#8217;s have another &#8216;global cache&#8217;. </p>
<p>To start with, the way I view JPA Persistence Context is&#8230;.</p>
<p>Persistence Context has 2 functions/jobs<br />
- Building &#8216;consistent&#8217; object graphs<br />
- in JPA used in flush to persist all &#8216;dirty&#8217; persistent objects</p>
<p>Persistence Context has 3 levels<br />
- Statement (my concept, not in JPA)<br />
- Transaction<br />
- Extended (across multiple transactions)</p>
<p>The way I see the issue you describe here Brian is:<br />
Either: You&#8217;d like to not have JPA flush dirty objects automatically.<br />
In the example, setName(&#8221;Bar&#8221;) means that Bar is used in the update.</p>
<p>Or: You want the query to run with &#8220;Statement level persistence context&#8221;.<br />
In the example the query runs in the same transaction and by default there is<br />
&#8216;Transaction Level persistence context&#8217;. As the object is already in the persistence<br />
context then the query returns the same instance.</p>
<p>It seems to me that if either of these options where available, they would<br />
resolve the issue you described?</p>
<p>Note: Statement level Persistence Context is NOT mentioned in JPA or<br />
anywhere else (that I know of). Its a concept I use. </p>
<p>I wrote this document on Persistence Context that may help (hopefully).<br />
<a href="http://www.avaje.org/persistencecontext.html" rel="nofollow">http://www.avaje.org/persistencecontext.html</a></p>
<p>Does any of that make sense?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
