<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.1" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: 10 things I learned about using Hibernate/JPA successfully</title>
	<link>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/</link>
	<description>Random posts about Java, software development, politics, and economics</description>
	<pubDate>Wed, 23 Jul 2008 21:49:17 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.1</generator>

	<item>
		<title>by: 9 Links Today (2008-01-23)</title>
		<link>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-14465</link>
		<pubDate>Wed, 23 Jan 2008 15:20:45 +0000</pubDate>
		<guid>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-14465</guid>
					<description>[...] 10 things I learned about using Hibernate/JPA successfully by SpencerUresk [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] 10 things I learned about using Hibernate/JPA successfully by SpencerUresk [&#8230;]
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: suresk</title>
		<link>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-14423</link>
		<pubDate>Tue, 22 Jan 2008 19:55:42 +0000</pubDate>
		<guid>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-14423</guid>
					<description>Good Questions.

&quot;What naming standards did you use? I can try and reinvent the wheel but why do that if you have already tackled this problem.&quot;

I don't necessarily know that *my* naming standards are the best - the important thing is to standardize on something. Some sample rules I like:

1. Use descriptive, intuitive names for things - even if the database doesn't.
2. Entities should be singular, OneToMany relationships plural.
3. No underscores, no redundant names (ie, if the entity is Course, don't name the description field courseDescription, just call it description).

&quot;Do you have an example when it would be better to use stored procedures?&quot;

When to use stored procs or functions will depend largely on your application and your database. I've worked on fairly large applications that never needed to use stored procs, or only used 1 or 2. If you need to operate on a lot of records at once, or use a lot of records to calculate something, stored procs can come in handy.

For example - One part of one application I worked on had to do with training. I needed to figure out how many people were scheduled for a course at a particular facility at a given date. Unfortunately, there were a lot of peculiarities in the data, so this couldn't be accomplished with a straightforward query, and it would have involved pulling back thousands of records from the database. In cases like this, a proc or a function will always be faster - sometimes significantly so.

&quot;What is a rich model exactly?&quot;

Several years ago, you started seeing trends with Hibernate and with EJB entities where your model objects would be containers of data and nothing else - no behavior. Rich domain modeling, in this context at least, entails adding behavior to your object. 

Simple example - Let's say you have a Course object, representing a training course, and a name is generated for it based off attributes for that particular Course. With anemic domain modeling we've seen in the past, that code would go in a service layer object. With rich domain modeling, that logic goes in the model class. The benefit is that it is more reusable, easier to refactor, and better organized to have it in the model class itself.

&quot;How did you decide whether to use JPA or native Hibernate? I understand JPA offers a subset of the Hibernate functionality so what did you decide on and why did you make that decision?&quot;

Well, keep in mind that if you use Hibernate's JPA implementation, you aren't necessarily forgoing extra Hibernate functionality - you can still use Hibernate specific functionality wherever you need it. Going with the JPA standard makes it easier to upgrade (and potentially change implementations) in the future.

&quot;We are very much for the DRY principle but how do you decide whether to leave the Oracle constraint in the database or migrate the logic to the Entity?&quot;

I think it is generally a good practice to have the validation rules in both places, even though it is a bit of duplication. I mean, what happens if you have stored procs hitting that same data? Or you have to write native SQL in some spots? Or if other projects end up hitting the same DB?

I hope those answers help.

- Spencer</description>
		<content:encoded><![CDATA[<p>Good Questions.</p>
<p>&#8220;What naming standards did you use? I can try and reinvent the wheel but why do that if you have already tackled this problem.&#8221;</p>
<p>I don&#8217;t necessarily know that *my* naming standards are the best - the important thing is to standardize on something. Some sample rules I like:</p>
<p>1. Use descriptive, intuitive names for things - even if the database doesn&#8217;t.<br />
2. Entities should be singular, OneToMany relationships plural.<br />
3. No underscores, no redundant names (ie, if the entity is Course, don&#8217;t name the description field courseDescription, just call it description).</p>
<p>&#8220;Do you have an example when it would be better to use stored procedures?&#8221;</p>
<p>When to use stored procs or functions will depend largely on your application and your database. I&#8217;ve worked on fairly large applications that never needed to use stored procs, or only used 1 or 2. If you need to operate on a lot of records at once, or use a lot of records to calculate something, stored procs can come in handy.</p>
<p>For example - One part of one application I worked on had to do with training. I needed to figure out how many people were scheduled for a course at a particular facility at a given date. Unfortunately, there were a lot of peculiarities in the data, so this couldn&#8217;t be accomplished with a straightforward query, and it would have involved pulling back thousands of records from the database. In cases like this, a proc or a function will always be faster - sometimes significantly so.</p>
<p>&#8220;What is a rich model exactly?&#8221;</p>
<p>Several years ago, you started seeing trends with Hibernate and with EJB entities where your model objects would be containers of data and nothing else - no behavior. Rich domain modeling, in this context at least, entails adding behavior to your object. </p>
<p>Simple example - Let&#8217;s say you have a Course object, representing a training course, and a name is generated for it based off attributes for that particular Course. With anemic domain modeling we&#8217;ve seen in the past, that code would go in a service layer object. With rich domain modeling, that logic goes in the model class. The benefit is that it is more reusable, easier to refactor, and better organized to have it in the model class itself.</p>
<p>&#8220;How did you decide whether to use JPA or native Hibernate? I understand JPA offers a subset of the Hibernate functionality so what did you decide on and why did you make that decision?&#8221;</p>
<p>Well, keep in mind that if you use Hibernate&#8217;s JPA implementation, you aren&#8217;t necessarily forgoing extra Hibernate functionality - you can still use Hibernate specific functionality wherever you need it. Going with the JPA standard makes it easier to upgrade (and potentially change implementations) in the future.</p>
<p>&#8220;We are very much for the DRY principle but how do you decide whether to leave the Oracle constraint in the database or migrate the logic to the Entity?&#8221;</p>
<p>I think it is generally a good practice to have the validation rules in both places, even though it is a bit of duplication. I mean, what happens if you have stored procs hitting that same data? Or you have to write native SQL in some spots? Or if other projects end up hitting the same DB?</p>
<p>I hope those answers help.</p>
<p>- Spencer
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Eric</title>
		<link>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-14416</link>
		<pubDate>Tue, 22 Jan 2008 13:22:01 +0000</pubDate>
		<guid>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-14416</guid>
					<description>Hi

Very good article. I have a few questions I want to ask but I could not find an email for you so I thought I would post them here and you can respond directly to me if you prefer.

I am working on adding a JPA/Hibernate layer to an existing database. The current system is simply two tier, Oracle and JSP. It makes use of a lot of stored procedures and the data set is massive and the structure is very much de-normalized.

2) Use (and enforce) good naming standards from the beginning.

What naming standards did you use? I can try and reinvent the wheel but why do that if you have already tackled this problem.

4) Let the database do the things it is good at.

very good example of when to let the database do the hard work. I am trying to avoid using stored procedures et al and so far it is working but we have not looked at performance issues. Do you have an example when it would be better to use stored procedures? The application we are using will have to load and update 100,000s rows at a time so i am wondering if letting Hibernate handle that is a good thing. If not do you have an example of doing this in a better way. I guess I am looking for more complicated examples.

10) Use rich domain modeling.

What is a rich model exactly? I have been surfing the web trying to find useful examples but all i am finding is really simple examples that don't really help unless you are trying to build a really simple book store ;-) . I have seen lots written about domain driven design and the use of POJO's and we are trying to use these patterns as much as possible but we feel we have not really grasped the concepts. Do you have an example of a class hierarchy or collaborators that make use of a rich model and that don't. A before and after comparison would be much appreciated.

A few more questions not directly related to your article but you may have tackled these as well:

a) How did you decide whether to use JPA or native Hibernate? I understand JPA offers a subset of the Hibernate functionality so what did you decide on and why did you make that decision?

b) We have lots of business logic in the database in the form of Oracle constraints and many stored procedures. We are very much for the DRY principle but how do you decide whether to leave the Oracle constraint in the database or migrate the logic to the Entity? I guess it may depend on who else uses the database but assuming we are (or will be) the sole users of the database, does removing the constraints leave the database naked in that the data is there but the logic governing the structures is elsewhere? How about if we want to to use .NET apps say and Java apps where we can't necessarily share the entities, where should this business logic be stored?

I know I have asked a lot of question but I am hoping you can shed some light on your experience.

Many thanks in advance.

Eric</description>
		<content:encoded><![CDATA[<p>Hi</p>
<p>Very good article. I have a few questions I want to ask but I could not find an email for you so I thought I would post them here and you can respond directly to me if you prefer.</p>
<p>I am working on adding a JPA/Hibernate layer to an existing database. The current system is simply two tier, Oracle and JSP. It makes use of a lot of stored procedures and the data set is massive and the structure is very much de-normalized.</p>
<p>2) Use (and enforce) good naming standards from the beginning.</p>
<p>What naming standards did you use? I can try and reinvent the wheel but why do that if you have already tackled this problem.</p>
<p>4) Let the database do the things it is good at.</p>
<p>very good example of when to let the database do the hard work. I am trying to avoid using stored procedures et al and so far it is working but we have not looked at performance issues. Do you have an example when it would be better to use stored procedures? The application we are using will have to load and update 100,000s rows at a time so i am wondering if letting Hibernate handle that is a good thing. If not do you have an example of doing this in a better way. I guess I am looking for more complicated examples.</p>
<p>10) Use rich domain modeling.</p>
<p>What is a rich model exactly? I have been surfing the web trying to find useful examples but all i am finding is really simple examples that don&#8217;t really help unless you are trying to build a really simple book store ;-) . I have seen lots written about domain driven design and the use of POJO&#8217;s and we are trying to use these patterns as much as possible but we feel we have not really grasped the concepts. Do you have an example of a class hierarchy or collaborators that make use of a rich model and that don&#8217;t. A before and after comparison would be much appreciated.</p>
<p>A few more questions not directly related to your article but you may have tackled these as well:</p>
<p>a) How did you decide whether to use JPA or native Hibernate? I understand JPA offers a subset of the Hibernate functionality so what did you decide on and why did you make that decision?</p>
<p>b) We have lots of business logic in the database in the form of Oracle constraints and many stored procedures. We are very much for the DRY principle but how do you decide whether to leave the Oracle constraint in the database or migrate the logic to the Entity? I guess it may depend on who else uses the database but assuming we are (or will be) the sole users of the database, does removing the constraints leave the database naked in that the data is there but the logic governing the structures is elsewhere? How about if we want to to use .NET apps say and Java apps where we can&#8217;t necessarily share the entities, where should this business logic be stored?</p>
<p>I know I have asked a lot of question but I am hoping you can shed some light on your experience.</p>
<p>Many thanks in advance.</p>
<p>Eric
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: links for 2007-08-14 &#171; On Being Ben</title>
		<link>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-7801</link>
		<pubDate>Tue, 14 Aug 2007 20:28:12 +0000</pubDate>
		<guid>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-7801</guid>
					<description>[...] 10 things I learned about using Hibernate/JPA successfully by SpencerUresk (tags: orm nhibernate) [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] 10 things I learned about using Hibernate/JPA successfully by SpencerUresk (tags: orm nhibernate) [&#8230;]
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Sarah</title>
		<link>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-7770</link>
		<pubDate>Mon, 13 Aug 2007 23:47:22 +0000</pubDate>
		<guid>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-7770</guid>
					<description>Just wanted to say that it was nice that you mentioned some 'non-technical' tips that are just as important. eg.. have a good relationship with the DBAs and the importance of managing expectations.  

:-)</description>
		<content:encoded><![CDATA[<p>Just wanted to say that it was nice that you mentioned some &#8216;non-technical&#8217; tips that are just as important. eg.. have a good relationship with the DBAs and the importance of managing expectations.  </p>
<p>:-)
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Another Digest On AJAX Tutorials</title>
		<link>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-7717</link>
		<pubDate>Sat, 11 Aug 2007 23:39:16 +0000</pubDate>
		<guid>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-7717</guid>
					<description>[...] 10 things I learned about using Hibernate/JPA successfully by SpencerUresk - I decided to share a few things I learned about using Hibernate/JPA in a large project with a complicated database setup [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] 10 things I learned about using Hibernate/JPA successfully by SpencerUresk - I decided to share a few things I learned about using Hibernate/JPA in a large project with a complicated database setup [&#8230;]
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Web Development Resorce Articles</title>
		<link>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-7690</link>
		<pubDate>Sat, 11 Aug 2007 01:32:48 +0000</pubDate>
		<guid>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-7690</guid>
					<description>[...] 10 things I learned about using Hibernate/JPA successfully by SpencerUresk - I decided to share a few things I learned about using Hibernate/JPA in a large project with a complicated database setup [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] 10 things I learned about using Hibernate/JPA successfully by SpencerUresk - I decided to share a few things I learned about using Hibernate/JPA in a large project with a complicated database setup [&#8230;]
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: links for 2007-08-09 &#171; betaalfa</title>
		<link>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-7643</link>
		<pubDate>Thu, 09 Aug 2007 04:27:16 +0000</pubDate>
		<guid>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-7643</guid>
					<description>[...] 10 things I learned about using Hibernate/JPA successfully by SpencerUresk (tags: hibernate tips) [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] 10 things I learned about using Hibernate/JPA successfully by SpencerUresk (tags: hibernate tips) [&#8230;]
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Vinny Carpenter&#8217;s blog &#187; Daily del.icio.us for Jul 30, 2007 through Aug 03, 2007</title>
		<link>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-7465</link>
		<pubDate>Sat, 04 Aug 2007 00:31:18 +0000</pubDate>
		<guid>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-7465</guid>
					<description>[...] 10 things I learned about using Hibernate/JPA successfully by SpencerUresk - I decided to share a few things I learned about using Hibernate/JPA in a large project with a complicated database setup [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] 10 things I learned about using Hibernate/JPA successfully by SpencerUresk - I decided to share a few things I learned about using Hibernate/JPA in a large project with a complicated database setup [&#8230;]
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Gavin King</title>
		<link>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-7382</link>
		<pubDate>Thu, 02 Aug 2007 05:18:05 +0000</pubDate>
		<guid>http://www.spenceruresk.com/2007/07/27/10-things-i-learned-about-using-hibernatejpa-successfully/#comment-7382</guid>
					<description>Nice article :-)</description>
		<content:encoded><![CDATA[<p>Nice article :-)
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
