<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>Narcanti</title>
	<atom:link href="http://narcanti.keyboardsamurais.de/feed" rel="self" type="application/rss+xml" />
	<link>http://narcanti.keyboardsamurais.de</link>
	<description>deep geeks click here</description>
	<lastBuildDate>Fri, 12 Mar 2010 13:55:04 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Etikettenschwindel bei Lebensmitteln</title>
		<link>http://narcanti.keyboardsamurais.de/etikettenschwindel-bei-lebensmitteln.html</link>
		<comments>http://narcanti.keyboardsamurais.de/etikettenschwindel-bei-lebensmitteln.html#comments</comments>
		<pubDate>Thu, 11 Mar 2010 19:50:02 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[Not lost but found]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=432</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/notlostbutfound.png" width="24" height="24" alt="" title="Not lost but found" /><br/>Zuf&#228;llig dar&#252;ber gestolpert: Auf www.abgespeist.de werden Werbekampagnen und Produkte von Lebensmittelherstellern unter die Lupe genommen. Interessant: Der &#8220;Rosa-Joghurt-Riegel&#8221; hat mehr Fett und Kallorien als Vollmilchschokolade und die N&#228;hrwertangaben fehlen nat&#252;rlich auf der Packung. Aber auch der neue Werbeslogan f&#252;r die Schokoriegel f&#252;r Kinder ist nicht schlecht: &#8220;Die Extra Portion Zucker und Fett!&#8221;.
]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/notlostbutfound.png" width="24" height="24" alt="" title="Not lost but found" /><br/><p>Zuf&#228;llig dar&#252;ber gestolpert: Auf <a href="http://www.abgespeist.de/alle_produkte/index_ger.html">www.abgespeist.de</a> werden Werbekampagnen und Produkte von Lebensmittelherstellern unter die Lupe genommen. Interessant: Der &#8220;Rosa-Joghurt-Riegel&#8221; hat mehr Fett und Kallorien als Vollmilchschokolade und die N&#228;hrwertangaben fehlen nat&#252;rlich auf der Packung. Aber auch der neue Werbeslogan f&#252;r die Schokoriegel f&#252;r Kinder ist nicht schlecht: &#8220;Die Extra Portion Zucker und Fett!&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/etikettenschwindel-bei-lebensmitteln.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hardening WordPress: Basic generator obfuscation</title>
		<link>http://narcanti.keyboardsamurais.de/hardening-wordpress-basic-generator-obfuscation.html</link>
		<comments>http://narcanti.keyboardsamurais.de/hardening-wordpress-basic-generator-obfuscation.html#comments</comments>
		<pubDate>Sun, 17 Jan 2010 20:56:38 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=429</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/wordpress-small.jpg" width="25" height="25" alt="" title="WordPress" /><br/>As previously noted, here another part of my Hardening WordPress series. This time I&#8217;ll show you the really basic technique of how you can obfuscate at least the generator-tag for your blog.

The generator tag is the one in the sourcecode with &#60;meta name=&#8221;generator&#8221; content=&#8221;Wordpress version&#8221;/&#62;. Ususally it should provide visitors or search engines some meta [...]]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/wordpress-small.jpg" width="25" height="25" alt="" title="WordPress" /><br/><p>As previously noted, here another part of my Hardening WordPress series. This time I&#8217;ll show you the really basic technique of how you can obfuscate at least the generator-tag for your blog.<br />
<span id="more-429"></span><br />
The generator tag is the one in the sourcecode with &lt;meta name=&#8221;generator&#8221; content=&#8221;Wordpress version&#8221;/&gt;. Ususally it should provide visitors or search engines some meta information on which software you use in which version. But it is also helpful to attackers. When they know which software in which version you use, they can reduce the attacks to known issues of this version. So it&#8217;s not a good idea to have this information in your blog. Also this information can help attackers to write scripts that will attack your blog on their own.</p>
<p>So the most basic step is to tell WordPress to remove this information, which is done by adding few methods into the functions.php within the theme folder (the plugin <a href="http://blogsecurity.net/wordpress/bs-wp-noversion">bs-wp-noversion</a> will do the same thing without modifying any theme files):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">remove_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_head'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rsd_link'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// remove Really Simple Discovery entry</span>
remove_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_head'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wlwmanifest_link'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// remove Windows Live Writer Link  </span>
remove_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_head'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wp_generator'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// remove Version output</span></pre></div></div>

<p>The most important thing here is that you removes the WordPress version from the header AND the feeds.<br />
And finally: Don&#8217;t forget to remove the files readme.html and license.txt from the root folder as an intruder may look at them to determine the version. Be aware: The removal of this files is needed everytime you update your Wordpress core.</p>
<p>Additionally you can include some fake generator-tags within the header of your theme, like:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;meta name=&quot;generator&quot; content=&quot;Movable Type v3.2&quot; /&gt;
&lt;meta name=&quot;generator&quot; content=&quot;Joomla! 1.5 - Open Source Content Management&quot; /&gt;
&lt;meta name=&quot;generator&quot; content=&quot;TYPO3 4.1 CMS&quot; /&gt;
&lt;meta name=&quot;generator&quot; content=&quot;Yahoo! SiteBuilder/2.4/1.5.0_02&quot; /&gt;
&lt;!-- 
	This website is powered by TYPO3 - inspiring people to share!
	TYPO3 is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.
	TYPO3 is copyright 1998-2006 of Kasper Skaarhoj. Extensions are copyright of their respective owners.
	Information and contribution at http://typo3.com/ and http://typo3.org/
--&gt;</pre></div></div>

<p>Unfortunately an intruder can detect the lots of &#8220;wp-includes&#8221; and &#8220;wp-content&#8221; etc. on your page to at least determine that you&#8217;re using WordPress. There are several other strategies to obfuscate your wordpress up to a point, where it is really difficult for some intruder to tell what blogging-software you use at all.<br />
But this extends, for now, the scope of this post (as it requires lots of changes on your theme and a lot of rewrite rules in your htaccess files to hide eveything).</p>
<p>Perhaps later on I&#8217;ll tie together some of my personal functions together to a plugin to do this automatically.</p>
]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/hardening-wordpress-basic-generator-obfuscation.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hardening WordPress the geek way</title>
		<link>http://narcanti.keyboardsamurais.de/hardening-wordpress-the-geek-way.html</link>
		<comments>http://narcanti.keyboardsamurais.de/hardening-wordpress-the-geek-way.html#comments</comments>
		<pubDate>Sun, 17 Jan 2010 20:30:16 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[mysql trigger]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=428</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/wordpress-small.jpg" width="25" height="25" alt="" title="WordPress" /><br/>My Wordpress installation was hacked several times, and all because I was too lazy to use basic protection and hardening mechanisms. After some time I decided to investigate more on the security of my blog and applied some well known protection techniques as well as some really geeky dirty hacks right in the database.

For the [...]]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/wordpress-small.jpg" width="25" height="25" alt="" title="WordPress" /><br/><p>My Wordpress installation was hacked several times, and all because I was too lazy to use basic protection and hardening mechanisms. After some time I decided to investigate more on the security of my blog and applied some well known protection techniques as well as some really geeky dirty hacks right in the database.<br />
<span id="more-428"></span><br />
For the first part of this series, I just want to show my really geeky dirty hackish database-level protection.<br />
Other not so geeky and more proper protection techniques can be found at:<br />
<dir></p>
<li><a href="http://blogsecurity.net/wordpress/wordpress-security-whitepaper">Security whitepaper for wordpress incl. several very usefull plugins</a></li>
<li><a href="http://www.erich-kachel.de/?p=763">interesting article</a></li>
<li><a href="http://wpantivirus.com/">first wordpress antivirus plugin</a></li>
<li><a href="http://php-ids.org/">PHPIDS &#8211; PHP based intrusion detection and prevention system</a></li>
<p></dir><br />
Perhaps I&#8217;ll cover few of them in later articles.</p>
<h1><a name="0">The dirty hack</a></h1>
<p>Ususally the blogs on my dedicated system are owned and used by only one person as they are personal blogs. So there is only need for two user accounts on a Wordpress install: One for the person owning the blog and one for the admin for maintainance purposes (like updating plugins and the WP core).<br />
When a blog is set up, changes on the wp_users are redundant for my blogs. Most hackers will try to create (by SQL-Injection) a new user with extended rights or modify the authentication data of existing users (like the one for admin). So I had the idea of preventing modifications on the wp_users. This only can be achieved within the database itself.<br />
After experimenting with the user rights in mysql (GRANT, REVOKE) I found out that restricting the access to only the wp_users table would need to set access rights to all other tables. No option for me.<br />
I investigated a little bit and found, that there is another possibility: TRIGGERS, which need at least mysql 5+ Version.<br />
In my database I have some administrator user who may do everything in the database, I&#8217;ll call this one &#8220;dba&#8221;. For the wordpress I create another user as described in the security whitepaper with less rights. Then I place a trigger on the wp_users table which avoids DELETE and INSERT except by the dba:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">delimiter <span style="color: #66cc66;">//</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> <span style="color: #ff0000;">`mywordpressdb`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`root_insert_only`</span> 
  BEFORE <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #ff0000;">`mywordpressdb`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`wp_users`</span>
  <span style="color: #993333; font-weight: bold;">FOR</span> EACH ROW BEGIN
    DECLARE dummy INT;
    <span style="color: #993333; font-weight: bold;">IF</span> STRCMP<span style="color: #66cc66;">&#40;</span>SUBSTRING<span style="color: #66cc66;">&#40;</span>SESSION_USER<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'dba@'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&lt;&gt;</span><span style="color: #cc66cc;">0</span> THEN
      <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'no'</span> <span style="color: #993333; font-weight: bold;">INTO</span> dummy <span style="color: #993333; font-weight: bold;">FROM</span> dual<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">WHERE</span> dual<span style="color: #66cc66;">.</span>id<span style="color: #66cc66;">=</span>NEW<span style="color: #66cc66;">.</span>id;
    END <span style="color: #993333; font-weight: bold;">IF</span>;
  END
<span style="color: #66cc66;">//</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> <span style="color: #ff0000;">`mywordpressdb`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`root_delete_only`</span> 
  BEFORE <span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #ff0000;">`mywordpressdb`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`wp_users`</span>
  <span style="color: #993333; font-weight: bold;">FOR</span> EACH ROW BEGIN
    DECLARE dummy INT;
    <span style="color: #993333; font-weight: bold;">IF</span> STRCMP<span style="color: #66cc66;">&#40;</span>SUBSTRING<span style="color: #66cc66;">&#40;</span>SESSION_USER<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'dba@'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&lt;&gt;</span><span style="color: #cc66cc;">0</span> THEN
      <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'no'</span> <span style="color: #993333; font-weight: bold;">INTO</span> dummy <span style="color: #993333; font-weight: bold;">FROM</span> dual<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">WHERE</span> dual<span style="color: #66cc66;">.</span>id<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">12</span>;
    END <span style="color: #993333; font-weight: bold;">IF</span>;
  END
<span style="color: #66cc66;">//</span>
&nbsp;
delimiter ;</pre></div></div>

<p>This both triggers only allow inserts and deletes by the dba user (who has to login into mysql by a shell account). All other users get some sql-error on trying it.<br />
As there was the admin-account reset bug in WP, and a SQL-injection could update an existing login account, I also added a trigger to updates. Since a blog-user may want to change his email or other account data (except password and login name), the trigger for updates restricts changes to that fields:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">delimiter <span style="color: #66cc66;">//</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> <span style="color: #ff0000;">`mywordpressdb`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`restricted_update_only`</span> 
  BEFORE <span style="color: #993333; font-weight: bold;">UPDATE</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #ff0000;">`mywordpressdb`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`wp_users`</span>
  <span style="color: #993333; font-weight: bold;">FOR</span> EACH ROW BEGIN
    DECLARE dummy INT;
    <span style="color: #993333; font-weight: bold;">IF</span> STRCMP<span style="color: #66cc66;">&#40;</span>SUBSTRING<span style="color: #66cc66;">&#40;</span>SESSION_USER<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'dba@'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&lt;&gt;</span><span style="color: #cc66cc;">0</span> THEN
      <span style="color: #993333; font-weight: bold;">SET</span> NEW<span style="color: #66cc66;">.</span>ID<span style="color: #66cc66;">=</span>OLD<span style="color: #66cc66;">.</span>ID;
      <span style="color: #993333; font-weight: bold;">SET</span> NEW<span style="color: #66cc66;">.</span>user_login<span style="color: #66cc66;">=</span>OLD<span style="color: #66cc66;">.</span>user_login;
      <span style="color: #993333; font-weight: bold;">SET</span> NEW<span style="color: #66cc66;">.</span>user_pass<span style="color: #66cc66;">=</span>OLD<span style="color: #66cc66;">.</span>user_pass;
      <span style="color: #993333; font-weight: bold;">SET</span> NEW<span style="color: #66cc66;">.</span>user_registered<span style="color: #66cc66;">=</span>OLD<span style="color: #66cc66;">.</span>user_registered;
      <span style="color: #993333; font-weight: bold;">SET</span> NEW<span style="color: #66cc66;">.</span>user_activation_key<span style="color: #66cc66;">=</span>OLD<span style="color: #66cc66;">.</span>user_activation_key;
      <span style="color: #993333; font-weight: bold;">SET</span> NEW<span style="color: #66cc66;">.</span>user_status<span style="color: #66cc66;">=</span>OLD<span style="color: #66cc66;">.</span>user_status;
    END <span style="color: #993333; font-weight: bold;">IF</span>;
  END
<span style="color: #66cc66;">//</span>
&nbsp;
delimiter ;</pre></div></div>

<p>The update trigger restricts changes to all fields but the ones set in the trigger itself. This hack prevents changing of login-accounts but to the cost of some comfort loss. If a user wants to change his password we now have to log into the database as user dba and execute some query. But at least, this gives some more security to our blog.</p>
<p>By the way: Since newer versions of WordPress use some different encryption for the passwords, you should use <a href="http://scriptserver.mainframe8.com/wordpress_password_hasher.php">a wordpress password hasher</a> instead of MD5 when updating user passwords manually.</p>
<p>Of course, this makes no sense if you use weak passwords and the intruder can apply some brute force or hash-lookup to find it, or if you have multiple users using one blog and you have to recently update login data or are no geek.</p>
]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/hardening-wordpress-the-geek-way.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hibernate DataViewObjects</title>
		<link>http://narcanti.keyboardsamurais.de/hibernate-dataviewobjects.html</link>
		<comments>http://narcanti.keyboardsamurais.de/hibernate-dataviewobjects.html#comments</comments>
		<pubDate>Sun, 17 Jan 2010 20:03:54 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=427</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/java-small.gif" width="25" height="40" alt="" title="Java" /><br/>When working with Hibernate and nested domain object models, it can be a performance problem when trying to display several (including nested) properties in a view. Usually for such cases the use of view objects is practical.
This is the first scetch of my idea to automate population of view objects with hibernate.

Meanwhile I worked out [...]]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/java-small.gif" width="25" height="40" alt="" title="Java" /><br/><p>When working with Hibernate and nested domain object models, it can be a performance problem when trying to display several (including nested) properties in a view. Usually for such cases the use of view objects is practical.<br />
This is the first scetch of my idea to automate population of view objects with hibernate.<br />
<span id="more-427"></span><br />
Meanwhile I worked out some extended example with the use of Annotations. However, the current form is not usefull enough, as using criterions for restrictions is quite difficult. But more details on the next part of this. Here the first one:</p>
<p>Assume we have some nested domain model consisting of a person, an address and a country as following:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@<span style="color: #003399;">Entity</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Person<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Long</span> id<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> firstname<span style="color: #339933;">:</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> lastName<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Date</span> birthdate<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> comment<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Address address<span style="color: #339933;">;</span>
&nbsp;
	@Id
	@GeneratedValue<span style="color: #009900;">&#40;</span>strategy<span style="color: #339933;">=</span>GenerationType.<span style="color: #006633;">AUTO</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Long</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> id<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// appropriate getters and setter for id,</span>
	<span style="color: #666666; font-style: italic;">// firstname, lastname, birthdate and comment</span>
&nbsp;
	@ManyToOne
	<span style="color: #000000; font-weight: bold;">public</span> Address getAddress<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> address<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@<span style="color: #003399;">Entity</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Address<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Long</span> id<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> street<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Country country<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// appropriate getters and setter for </span>
	<span style="color: #666666; font-style: italic;">// id, street and country</span>
&nbsp;
	@ManyToOne
	<span style="color: #000000; font-weight: bold;">public</span> Country getCountry<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> country<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@<span style="color: #003399;">Entity</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Country<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> iso3166<span style="color: #339933;">;</span> 
	<span style="color: #666666; font-style: italic;">// iso 3166 2 letter code </span>
	<span style="color: #666666; font-style: italic;">// (uppercase), like DE for Germany</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> name<span style="color: #339933;">;</span>
&nbsp;
	@Id
	@Column<span style="color: #009900;">&#40;</span>length<span style="color: #339933;">=</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getIso3166<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> iso3166<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// appropriate getters and setter for name and iso3166</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now let&#8217;s assume we want to build a list displaying only the lastname and the countryname of a person. In such a case it&#8217;s unneccessary to do a query like &#8220;SELECT p FROM Person p&#8221;, since even if lazy loading is enabled, hibernate will load all properties leading to lot&#8217;s of unneeded data transported from database to application.<br />
In such a case we would prefer to build a view object, that only will hold the information we need to display:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PersonLastNameCountryViewObject<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> lastName<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> countryName<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// appropriate getters and setter</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>So we now have a lightweight view object, but how do we get the data into it?<br />
One possibility would be to build a custom query for this, like:</p>
<pre>
SELECT p.lastName, c.name FROM Person p LEFT JOIN p.address AS a LEFT JOIN a.country AS c
</pre>
<p>This would give us the needed data and we only would have to map the results to our view object.<br />
Having several views may lead to lots of custom queries and code doing the retrieval and mapping stuff. So why not automating it?</p>
<p>I created some classes to handle this work, but there are few informations that have to be given to it, especially about which view object properties to map to which domain model properties.<br />
In the above view object example, I decided to use a map of view object properties and define a domain model path for each, just like in commons-beanutils.<br />
The mapping for the above example would be:</p>
<pre>
lastName -> lastName
countryName -> address.country.name
</pre>
<p>The path here starts with the initial domain class, in this case the Person class. Since Hibernate does not support nested object paths like in</p>
<pre>
SELECT p.name, p.address.country.name FROM Person p
</pre>
<p>I built some code to split the path and join the appropriate domain models into the query just to have the working query denoted previously.<br />
So my view object mapping helpers contain of following classes:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Just an interface that will create a </span>
<span style="color: #666666; font-style: italic;">// view object for us for each resultset row</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> ViewObjectFactory<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> createNewViewObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// a cimple class to hold all ,eta data needed for building our view objects</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ViewObjectMetaData<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// This will hold the mappings like</span>
  <span style="color: #666666; font-style: italic;">// lastName -&gt; lastName</span>
  <span style="color: #666666; font-style: italic;">// countryName -&gt; address.country.name</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> HashMap<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span> 
    propertiesToObjectPaths <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// this will hold our initial domain class, like Person.class.</span>
  <span style="color: #666666; font-style: italic;">// we need this to create a criteria in hibernate later on</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">Class</span> domainClass<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// the factory we will use to create the view objects</span>
  <span style="color: #000000; font-weight: bold;">private</span> ViewObjectFactory voFactory<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// as default, if no object paths are given, we assume that each view object property</span>
  <span style="color: #666666; font-style: italic;">// will be mapped non-nestingly to the domain class propertys with the same name.</span>
  <span style="color: #666666; font-style: italic;">// so the mapping will be something like:</span>
  <span style="color: #666666; font-style: italic;">// propertyA -&gt; propertyA</span>
  <span style="color: #666666; font-style: italic;">// propertyB -&gt; propertyB</span>
  <span style="color: #666666; font-style: italic;">// will need BeanUtils to work, or make some own code with reflection</span>
  <span style="color: #000000; font-weight: bold;">public</span> ViewObjectMetaData<span style="color: #009900;">&#40;</span>ViewObjectFactory voFactory, 
    <span style="color: #000000; font-weight: bold;">Class</span> domainClass<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">voFactory</span> <span style="color: #339933;">=</span> voFactory<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">domainClass</span> <span style="color: #339933;">=</span> domainClass<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003399;">Map</span> desc <span style="color: #339933;">=</span> BeanUtils.<span style="color: #006633;">describe</span><span style="color: #009900;">&#40;</span>dtoFactory.<span style="color: #006633;">createDto</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      desc.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;class&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">final</span> Collection<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> properties <span style="color: #339933;">=</span> 
        <span style="color: #009900;">&#40;</span>Collection<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> desc.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> property<span style="color: #339933;">:</span>properties<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        propertiesToObjectPaths.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>property, property<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// just make a runtime exception from it...</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e <span style="color: #000000; font-weight: bold;">instanceof</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#41;</span> e<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">RuntimeException</span> r <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        r.<span style="color: #006633;">setStackTrace</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">throw</span> r<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> ViewObjectMetaData<span style="color: #009900;">&#40;</span>ViewObjectFactory voFactory, 
    <span style="color: #000000; font-weight: bold;">Class</span> domainClass, 
    Map<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span> propertiesToObjectPaths<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">voFactory</span> <span style="color: #339933;">=</span> voFactory<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">domainClass</span> <span style="color: #339933;">=</span> domainClass<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">propertiesToObjectPaths</span>.<span style="color: #006633;">putAll</span><span style="color: #009900;">&#40;</span>propertiesToObjectPaths<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// appropriate getters</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now we have all information needed to build up queries and populate the view objects. The main work will consist of building up the query from the object path and mapping the resultset to the view objects.<br />
For building the query, I used the criteria API of hibernate, which allows to add further restrictions on the query later on. The algorithm for transforming the object path to a criteria is not that complicated. We have to think about two different cases in the object path:</p>
<p>1. object path consists of one part, like &#8220;lastName&#8221;. This has to be mapped to a projection, like:</p>
<pre>
SELECT p.lastName FROM Person p
</pre>
<p>2. the object consists of multiple parts, like &#8220;address.street&#8221; or &#8220;address.country.name&#8221;. In this case we have to create a hibernate alias (which internally maps to a join) for each part except the first (which is the root domain class) and the last, which has to be added as a projection as it is the property we want to have. So we have for the two part object path example:</p>
<pre>
SELECT a.street FROM Person p LEFT JOIN p.address AS a
</pre>
<p>and the three part object path example:</p>
<pre>
SELECT c.name FROM Person p LEFT JOIN p.address AS a LEFT JOIN a.country AS c
</pre>
<p>Also we&#8217;ll keep track of the indices of the projected properties in the resultset for the mapping between resultset and viewobject</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ViewObjectCriteriaBuilder<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// just a helper class to transport </span>
  <span style="color: #666666; font-style: italic;">// criteria and columnmappings</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> ViewObjectCriteria<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Criteria criteria<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> HashMap<span style="color: #339933;">&lt;</span>String, Integer<span style="color: #339933;">&gt;</span> propertyToColumnMappings <span style="color: #339933;">=</span> 
      <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, Integer<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// apropriate getters/setters</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> SessionFactory sessionFactory<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// appropriate setter for the sessionFactory </span>
  <span style="color: #666666; font-style: italic;">// or just pass a current session to the next method</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> ViewObjectCriteria buildCriteria<span style="color: #009900;">&#40;</span>ViewObjectMetaData voMetaData<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">final</span> ViewObjectCriteria voCriteria <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ViewObjectCriteria<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">final</span> Criteria criteria <span style="color: #339933;">=</span> sessionFactory.
      <span style="color: #006633;">getCurrentSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.
      <span style="color: #006633;">createCriteria</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;d&quot;</span>, voMetaData.<span style="color: #006633;">getDomainClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    voCriteria.<span style="color: #006633;">setCriteria</span><span style="color: #009900;">&#40;</span>criteria<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">final</span> Map<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span> propertiesToObjectPaths <span style="color: #339933;">=</span> 
      voMetaData.<span style="color: #006633;">getPropertiesToObjectPaths</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// our projections</span>
    <span style="color: #000000; font-weight: bold;">final</span> ProjectionList projections <span style="color: #339933;">=</span> Projections.<span style="color: #006633;">projectionList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// max. amount of aggregations in object path</span>
    <span style="color: #000066; font-weight: bold;">int</span> maxAggregationDeepth <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// index of property in resultset</span>
    <span style="color: #000066; font-weight: bold;">int</span> propertyColumnIndex <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003399;">String</span> objectPath<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// objectpath of current vo property</span>
    <span style="color: #666666; font-style: italic;">// amount of aggregations in current object path</span>
    <span style="color: #000066; font-weight: bold;">int</span> aggregationDeepth<span style="color: #339933;">;</span> 
    <span style="color: #000000; font-weight: bold;">final</span> ArrayList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> aggregationParts <span style="color: #339933;">=</span> 
      <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// parts of the object path, splitted</span>
&nbsp;
&nbsp;
    <span style="color: #666666; font-style: italic;">// in the first step we only collect information </span>
    <span style="color: #666666; font-style: italic;">// about the needed aggregations,</span>
    <span style="color: #666666; font-style: italic;">// the joins will be build later on</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> property<span style="color: #339933;">:</span>propertiesToObjectPaths.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      objectPath <span style="color: #339933;">=</span> propertiesToObjectPaths.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>property<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// this helper just counts the </span>
      <span style="color: #666666; font-style: italic;">// occurences of '.' in the objectPath</span>
      aggregationDeepth <span style="color: #339933;">=</span> StringUtil.<span style="color: #006633;">occurences</span><span style="color: #009900;">&#40;</span>objectPath, <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>aggregationDeepth<span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// no aggregation, like</span>
        <span style="color: #666666; font-style: italic;">// lastName -&gt; d.lastName</span>
        projections.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;d.&quot;</span><span style="color: #339933;">+</span>objectPath<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
        maxAggregationDeepth <span style="color: #339933;">=</span> 
          <span style="color: #003399;">Math</span>.<span style="color: #006633;">max</span><span style="color: #009900;">&#40;</span>maxAggregationDeepth, aggregationDeepth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// aggregations exist</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// first split the object path</span>
        aggregationParts.<span style="color: #006633;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// this helper splits the objectPath </span>
        <span style="color: #666666; font-style: italic;">// on &quot;\\.&quot; and adds all parts to the </span>
        <span style="color: #666666; font-style: italic;">// aggregationParts-list. Works the same </span>
        <span style="color: #666666; font-style: italic;">// way as String.split</span>
        CollectionSplitter.<span style="color: #006633;">toList</span><span style="color: #009900;">&#40;</span>aggregationParts, objectPath, <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// last aggregations alias</span>
        <span style="color: #003399;">String</span> lastAggregationName <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> currentAggregationPart, currentAggregationName<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// when we're here, there are at least two parts in the object path</span>
        <span style="color: #666666; font-style: italic;">// first part is an property of the </span>
        <span style="color: #666666; font-style: italic;">// root domain class, e. g. address -&gt; d.address</span>
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> aggregationIndex<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> 
          aggregationIndex<span style="color: #339933;">&lt;=</span>aggregationDeepth<span style="color: #339933;">;</span> aggregationIndex<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
          currentAggregationPart <span style="color: #339933;">=</span> aggregationParts.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>aggregationIndex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>aggregationIndex<span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// equals to &quot;LEFT JOIN d.address AS ag_address&quot;</span>
            lastAggregationName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ag_&quot;</span><span style="color: #339933;">+</span>currentAggregationPart<span style="color: #339933;">;</span>
            aggregations.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>
              <span style="color: #0000ff;">&quot;d.&quot;</span><span style="color: #339933;">+</span>currentAggregationPart, 
              lastAggregationName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
          <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>aggregationIndex<span style="color: #339933;">==</span>aggregationDeepth<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// last part in object path, which </span>
            <span style="color: #666666; font-style: italic;">// denotes a property we want to have projected</span>
            <span style="color: #666666; font-style: italic;">// equals to &quot;SELECT ... ag_address_country.name FROM ...&quot;</span>
            projections.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>
              Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span>
                lastAggregationName<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">+</span>currentAggregationPart<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
          <span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// somewhere in the middle</span>
            <span style="color: #666666; font-style: italic;">// equals to </span>
            <span style="color: #666666; font-style: italic;">// &quot;LEFT JOIN ag_address.country AS ag_address_country&quot;</span>
            currentAggregationName <span style="color: #339933;">=</span> 
              lastAggregationName<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;_&quot;</span><span style="color: #339933;">+</span>currentAggregationPart<span style="color: #339933;">;</span>
            aggregations.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>
              lastAggregationName<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">+</span>currentAggregationPart, 
              currentAggregationName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            lastAggregationName <span style="color: #339933;">=</span> currentAggregationName<span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// update index of property in resultset</span>
      voCriteria.<span style="color: #006633;">getPropertyToColumnMappings</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.
        <span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>property, propertyColumnIndex<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// if there are any aggregations, we have</span>
    <span style="color: #666666; font-style: italic;">// to add an alias for each to the criteria</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>maxAggregationDeepth<span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// sort aggregatios (joins) by their alias length</span>
      <span style="color: #666666; font-style: italic;">// this is to enshure that ag_address is </span>
      <span style="color: #666666; font-style: italic;">// added before ag_address_country</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">final</span> List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> aggregationsSizeSorted <span style="color: #339933;">=</span> 
        <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>aggregations.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #003399;">Collections</span>.<span style="color: #006633;">sort</span><span style="color: #009900;">&#40;</span>aggregationsSizeSorted, 
        <span style="color: #666666; font-style: italic;">// the string length comparator just compares</span>
        <span style="color: #666666; font-style: italic;">// the length of two strings</span>
        <span style="color: #000000; font-weight: bold;">new</span> StringLengthComparator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> fromAggregation<span style="color: #339933;">:</span>aggregationsSizeSorted<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// here we also may use LEFT JOIN or some other join type</span>
        criteria.<span style="color: #006633;">createAlias</span><span style="color: #009900;">&#40;</span>
          fromAggregation, 
          aggregations.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>fromAggregation<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// add projections to criteria</span>
    criteria.<span style="color: #006633;">setProjection</span><span style="color: #009900;">&#40;</span>projections<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">return</span> voCriteria<span style="color: #339933;">;</span>    
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now we have build a criteria which will load all neccessary data from the database. Meanwhile we could add some restrictions or limitations to the query to only retrieve a portion of all rows. Somewhere all along the code we will need to have a valid session/transaction, but I&#8217;ll skip that, as this is just an example.</p>
<p>Next we build a class that will execute the criteria and map the columns from the resultset to the viewobjects. Here are several possibilites. For example using a special hibernate rowsetmapper, but the way I did it below also works fine.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> buildViewObjects<span style="color: #009900;">&#40;</span>ViewObjectCriteria voCriteria, 
  ViewObjectMetaData voMetaData<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
  ScrollableResults result <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
    Criteria criteria <span style="color: #339933;">=</span> voCriteria.<span style="color: #006633;">getCriteria</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Map<span style="color: #339933;">&lt;</span>String, Integer<span style="color: #339933;">&gt;</span> propertyColumnMappings <span style="color: #339933;">=</span> 
      voCriteria.<span style="color: #006633;">getPropertyColumnMappings</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// some cache method or scroll lock method here, if needed</span>
    result <span style="color: #339933;">=</span> criteria.<span style="color: #006633;">scroll</span><span style="color: #009900;">&#40;</span>ScrollMode.<span style="color: #006633;">FORWARD_ONLY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">Object</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> rowdata<span style="color: #339933;">;</span>
    <span style="color: #003399;">Object</span> resultObject<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">ArrayList</span> viewObjects <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>result.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      rowdata <span style="color: #339933;">=</span> result.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      resultObject <span style="color: #339933;">=</span> voMetaData.<span style="color: #006633;">getViewObjectFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.
        <span style="color: #006633;">createNewViewObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> property<span style="color: #339933;">:</span>
        propertyColumnMapping.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #666666; font-style: italic;">// also possible via reflection</span>
          PropertyUtils.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span>resultObject, 
            property, rowdata<span style="color: #009900;">&#91;</span>propertyColumnMappings.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>property<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>LOG.<span style="color: #006633;">isErrorEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            LOG.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;While setting property <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">+</span>
              property<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> from column <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">+</span>
              propertyColumnMapping.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>property<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>, e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
          resultObject <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>resultObject<span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        viewObjects.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>resultObject<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">return</span> viewObjects<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">finally</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>result<span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      result.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>That&#8217;s it (for now).</p>
<p>Limitations:<br />
<dir></p>
<li>the datatype of the setter in the view object has to be the same as in the corresponding domain property</li>
<li>restricting the query is quite difficult, as you don&#8217;t know the aliases of the generated aggregations a priori</li>
<p></dir></p>
<p>Further improvements could be:<br />
<dir></p>
<li>some annotations so that we just annotate our view object and rest is done in background</li>
<li>make a full working open-source API out of it</li>
<li>optimizations on the queries. if we only would like to select the id of a nested domain class, like &#8220;address.id&#8221;, which already is known to the Person table (since this is the referencing foreign key), it would be great not to have to join the addresses</li>
<li>automatic mapping between differring property types of view object and domain object (eg. long to string convertions)</li>
<li>improve the possibility to restrict the generated query</li>
<p></dir></p>
]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/hibernate-dataviewobjects.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Dateformatting</title>
		<link>http://narcanti.keyboardsamurais.de/javascript-dateformatting.html</link>
		<comments>http://narcanti.keyboardsamurais.de/javascript-dateformatting.html#comments</comments>
		<pubDate>Sun, 17 Jan 2010 19:56:40 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[Computer]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=426</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/binary.gif" width="22" height="22" alt="" title="Computer" /><br/>I just recognized that there is no convenient method in Javascript to format a date-object to a string with the help of a dateformat-pattern, like in java.text.SimpleDateFormat. So I have writen a simple method, which just does this, including most important patterns.


/*
Usage:
formatDate(new Date(), 'yyyy/MM/dd HH:mm:ss.SSS');
will return current date as something like '2010/01/01 14:41:52.957'.
&#160;
Implemented:
y  	Year [...]]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/binary.gif" width="22" height="22" alt="" title="Computer" /><br/><p>I just recognized that there is no convenient method in Javascript to format a date-object to a string with the help of a dateformat-pattern, like in java.text.SimpleDateFormat. So I have writen a simple method, which just does this, including most important patterns.<br />
<span id="more-426"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
Usage:
formatDate(new Date(), 'yyyy/MM/dd HH:mm:ss.SSS');
will return current date as something like '2010/01/01 14:41:52.957'.
&nbsp;
Implemented:
y  	Year 	Year  	1996 (by using yyyy); 96 (by using yy)
M 	Month in year 	Month 	7 or 10 (by using M); 07 or 10 (by using MM)
d 	Day in month 	Number 	7 or 10 (by using d); 07 or 10 (by using dd)
H 	Hour in day (0-23) 	Number 	7 or 10 (by using H); 07 or 10 (by using HH)
k 	Hour in day (1-24) 	Number 	7 or 10 (by using k); 07 or 10 (by using kk)
m 	Minute in hour 	Number 	7 or 10 (by using m); 07 or 10 (by using mm)
s 	Second in minute 	Number 	7 or 10 (by using s); 07 or 10 (by using ss)
S 	Millisecond 	Number 	 7 or 10 or 100 (by using S); 07 or 10 or 100 (by using SS); 007 or 010 or 100 (by using SSS);
&nbsp;
Not implemented:
M 	Month in year 	Month 	July; Jul; textual values (by using MMM or MMMM)
G  	Era designator 	Text  	AD
w 	Week in year 	Number 	27
W 	Week in month 	Number 	2
D 	Day in year 	Number 	189
F 	Day of week in month 	Number 	2
E 	Day in week 	Text 	Tuesday; Tue
a 	Am/pm marker 	Text 	PM
K 	Hour in am/pm (0-11) 	Number 	0
h 	Hour in am/pm (1-12) 	Number 	12
 * */</span>
<span style="color: #003366; font-weight: bold;">function</span> formatDate<span style="color: #009900;">&#40;</span>date<span style="color: #339933;">,</span> format<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> dayInMonth <span style="color: #339933;">=</span> date.<span style="color: #660066;">getDate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fullDayInMonth <span style="color: #339933;">=</span> dayInMonth<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fullDayInMonth.<span style="color: #660066;">length</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		fullDayInMonth <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">+</span>fullDayInMonth<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #003366; font-weight: bold;">var</span> month <span style="color: #339933;">=</span> date.<span style="color: #660066;">getMonth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fullMonth <span style="color: #339933;">=</span> month<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fullMonth.<span style="color: #660066;">length</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		fullMonth <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">+</span>fullMonth<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fullYear <span style="color: #339933;">=</span> date.<span style="color: #660066;">getFullYear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> year <span style="color: #339933;">=</span> fullYear.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> hour <span style="color: #339933;">=</span> date.<span style="color: #660066;">getHours</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fullHour <span style="color: #339933;">=</span> hour<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fullHour.<span style="color: #660066;">length</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		fullHour <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">+</span>fullHour<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #003366; font-weight: bold;">var</span> khour <span style="color: #339933;">=</span> hour<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fullKhour <span style="color: #339933;">=</span> khour<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fullKhour.<span style="color: #660066;">length</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		fullKhour <span style="color: #339933;">=</span> fullKhour<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> minutes <span style="color: #339933;">=</span> date.<span style="color: #660066;">getMinutes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fullMinutes <span style="color: #339933;">=</span> minutes<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fullMinutes.<span style="color: #660066;">length</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		fullMinutes <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">+</span>fullMinutes<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #003366; font-weight: bold;">var</span> seconds <span style="color: #339933;">=</span> date.<span style="color: #660066;">getSeconds</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fullSeconds <span style="color: #339933;">=</span> seconds<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fullSeconds.<span style="color: #660066;">length</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		fullSeconds <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">+</span>seconds<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #003366; font-weight: bold;">var</span> millis <span style="color: #339933;">=</span> date.<span style="color: #660066;">getMilliseconds</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fullMillis1 <span style="color: #339933;">=</span> millis<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fullMillis1.<span style="color: #660066;">length</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		fullMillis1 <span style="color: #339933;">=</span> <span style="color: #3366CC;">'0'</span><span style="color: #339933;">+</span>fullMillis1<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #003366; font-weight: bold;">var</span> fullMillis2 <span style="color: #339933;">=</span> fullMillis1<span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fullMillis2.<span style="color: #660066;">length</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		fullMillis2 <span style="color: #339933;">=</span> <span style="color: #3366CC;">'0'</span><span style="color: #339933;">+</span>fullMillis2<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> result <span style="color: #339933;">=</span> format<span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/MM/g</span><span style="color: #339933;">,</span> fullMonth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/M/g</span><span style="color: #339933;">,</span> month<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/yyyy/g</span><span style="color: #339933;">,</span> fullYear<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/yy/g</span><span style="color: #339933;">,</span> year<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/dd/g</span><span style="color: #339933;">,</span> fullDayInMonth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/d/g</span><span style="color: #339933;">,</span> dayInMonth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/HH/g</span><span style="color: #339933;">,</span> fullHour<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/H/g</span><span style="color: #339933;">,</span> hour<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/kk/g</span><span style="color: #339933;">,</span> fullKhour<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/k/g</span><span style="color: #339933;">,</span> khour<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/mm/g</span><span style="color: #339933;">,</span> fullMinutes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/m/g</span><span style="color: #339933;">,</span> minutes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/ss/g</span><span style="color: #339933;">,</span> fullSeconds<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/s/g</span><span style="color: #339933;">,</span> seconds<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/SSS/g</span><span style="color: #339933;">,</span> fullMillis2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/SS/g</span><span style="color: #339933;">,</span> fullMillis1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> result.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/S/g</span><span style="color: #339933;">,</span> millis<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/javascript-dateformatting.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring Acegi/Security auto-login</title>
		<link>http://narcanti.keyboardsamurais.de/spring-acegisecurity-auto-login.html</link>
		<comments>http://narcanti.keyboardsamurais.de/spring-acegisecurity-auto-login.html#comments</comments>
		<pubDate>Sun, 17 Jan 2010 17:40:18 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[acegi]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[spring security]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=425</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/java-small.gif" width="25" height="40" alt="" title="Java" /><br/>Usefull and thus noted:
In one of my current workprojects I had a registrationform the user filled. After formvalidation, I wanted to login the user automatically. This can be achieved in Spring / Acegi quite easy:


User user = createUser&#40;&#41;;
final RememberMeAuthenticationToken auth = new RememberMeAuthenticationToken&#40;webKey, userAccount.getUser&#40;&#41;, userAccount.getUser&#40;&#41;.getAuthorities&#40;&#41;&#41;; 
auth.setAuthenticated&#40;true&#41;; 
SecurityContextHolder.getContext&#40;&#41;.setAuthentication&#40;auth&#41;;

Also logging user out (after database new creattion or [...]]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/java-small.gif" width="25" height="40" alt="" title="Java" /><br/><p>Usefull and thus noted:<br />
In one of my current workprojects I had a registrationform the user filled. After formvalidation, I wanted to login the user automatically. This can be achieved in Spring / Acegi quite easy:<br />
<span id="more-425"></span></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">User user <span style="color: #339933;">=</span> createUser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">final</span> RememberMeAuthenticationToken auth <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RememberMeAuthenticationToken<span style="color: #009900;">&#40;</span>webKey, userAccount.<span style="color: #006633;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, userAccount.<span style="color: #006633;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getAuthorities</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
auth.<span style="color: #006633;">setAuthenticated</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
SecurityContextHolder.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setAuthentication</span><span style="color: #009900;">&#40;</span>auth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Also logging user out (after database new creattion or session invalidation):</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">SecurityContextHolder.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setAuthentication</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/spring-acegisecurity-auto-login.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Collections</title>
		<link>http://narcanti.keyboardsamurais.de/java-collections.html</link>
		<comments>http://narcanti.keyboardsamurais.de/java-collections.html#comments</comments>
		<pubDate>Sun, 08 Nov 2009 20:02:43 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=423</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/java-small.gif" width="25" height="40" alt="" title="Java" /><br/>Derzeit arbeite ich viel mit Java 1.5. Durch das Interface Iterable kann man hier die kurze Schleifenvariante

Collection c = ...
for &#40;final Object o:c&#41;&#123;
  ...
&#125;

einsetzen, die genauso auch f&#252;r Arrays funktioniert.
Was jedoch nicht geht, ist das Hinzuf&#252;gen von Arrays in Collections via collection.addAll(anArray);.
Hier hilft meine kleine Utilityklasse Collections weiter, die auch die Collection zur&#252;ck liefert.
Zwei [...]]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/java-small.gif" width="25" height="40" alt="" title="Java" /><br/><p>Derzeit arbeite ich viel mit Java 1.5. Durch das Interface Iterable kann man hier die kurze Schleifenvariante</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Collection</span> c <span style="color: #339933;">=</span> ...
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Object</span> o<span style="color: #339933;">:</span>c<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  ...
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>einsetzen, die genauso auch f&#252;r Arrays funktioniert.<br />
Was jedoch nicht geht, ist das Hinzuf&#252;gen von Arrays in Collections via <code lang="java">collection.addAll(anArray);</code>.<br />
Hier hilft meine kleine Utilityklasse Collections weiter, die auch die Collection zur&#252;ck liefert.<br />
Zwei Dinge, die man bei java.util.Collections leider nicht bedacht hat&#8230;<br />
<span id="more-423"></span></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Collection</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">class</span> <span style="color: #003399;">Collections</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Collections</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
  @SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&quot;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Collection</span> add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Collection</span> collection, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Object</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> values<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Object</span> value<span style="color: #339933;">:</span>values<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      collection.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">return</span> collection<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  @SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&quot;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Map</span> put<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Map</span> map, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Object</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> keys, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Object</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> values<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>keys.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      map.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>keys<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>, values<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">return</span> map<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Collection</span> remove<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Collection</span> collection, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Object</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> values<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Object</span> value<span style="color: #339933;">:</span>values<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      collection.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">return</span> collection<span style="color: #339933;">;</span> 
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/java-collections.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hibernate Deeper OrderBy</title>
		<link>http://narcanti.keyboardsamurais.de/hibernate-deeper-orderby.html</link>
		<comments>http://narcanti.keyboardsamurais.de/hibernate-deeper-orderby.html#comments</comments>
		<pubDate>Sun, 08 Nov 2009 19:50:01 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=422</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/java-small.gif" width="25" height="40" alt="" title="Java" /><br/>Hibernate unterst&#252;tzt in der Criteria API bei der Angabe von Properties f&#252;r Criterions oder auch Sortierungen lediglich die Angabe von Properties der Tiefe 1.
Beispielsweise ist criteria.addOrder(Order.asc("id")) m&#246;glich, jedoch criteria.addOrder(Order.asc("parent.id")) oder gar criteria.addOrder(Order.asc("parent.parent.id")) nicht m&#246;glich.
Um diese Abbilden zu k&#246;nnen, muss man sich einiger Joins oder Aliase bedienen.
Im folgenden wird dies anhand der Sortierung gel&#246;st.

Angenommen wir erhalten [...]]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/java-small.gif" width="25" height="40" alt="" title="Java" /><br/><p>Hibernate unterst&#252;tzt in der Criteria API bei der Angabe von Properties f&#252;r Criterions oder auch Sortierungen lediglich die Angabe von Properties der Tiefe 1.<br />
Beispielsweise ist <code lang="java">criteria.addOrder(Order.asc("id"))</code> m&#246;glich, jedoch <code lang="java">criteria.addOrder(Order.asc("parent.id"))</code> oder gar <code lang="java">criteria.addOrder(Order.asc("parent.parent.id"))</code> nicht m&#246;glich.<br />
Um diese Abbilden zu k&#246;nnen, muss man sich einiger Joins oder Aliase bedienen.<br />
Im folgenden wird dies anhand der Sortierung gel&#246;st.<br />
<span id="more-422"></span><br />
Angenommen wir erhalten das Sortierkriterium als String orderBy, welches eine Property oder einen Property-Pfad f&#252;r das entsprechende Attribut enth&#228;lt.<br />
So k&#246;nnen mit Hilfe eines simplen &#8220;Parsers&#8221; die ben&#246;tigten Aliase f&#252;r Joins hinzugef&#252;gt werden.<br />
Die Hilfsmethode StringUtil.occurences(String s, char c) z&#228;hlt lediglich die Vorkommen von c in s.<br />
Zus&#228;tzlich wird in boolean asc hinterlegt, ob absteigend (true) oder aufsteigend (false) sortiert wird.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">final</span> Criteria criteria <span style="color: #339933;">=</span> getCurrentSession<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">createCriteria</span><span style="color: #009900;">&#40;</span>MyDomain.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #0000ff;">&quot;d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// d ist alias für unser domain objekt</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>orderBy<span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> orderBy.<span style="color: #006633;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// erlaubt die benutzung von z. b. d.parent.object.name zum sortieren</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>StringUtil.<span style="color: #006633;">occurences</span><span style="color: #009900;">&#40;</span>orderBy, <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> parts <span style="color: #339933;">=</span> orderBy.<span style="color: #006633;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    criteria.<span style="color: #006633;">createAlias</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;d.&quot;</span><span style="color: #339933;">+</span>parts<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>, <span style="color: #0000ff;">&quot;x&quot;</span><span style="color: #339933;">+</span>parts<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> t<span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> t<span style="color: #339933;">&lt;=</span>parts.<span style="color: #006633;">length</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span> t<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      criteria.<span style="color: #006633;">createAlias</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;x&quot;</span><span style="color: #339933;">+</span>parts<span style="color: #009900;">&#91;</span>t<span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">+</span>parts<span style="color: #009900;">&#91;</span>t<span style="color: #009900;">&#93;</span>, <span style="color: #0000ff;">&quot;x&quot;</span><span style="color: #339933;">+</span>parts<span style="color: #009900;">&#91;</span>t<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    orderBy <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;x&quot;</span><span style="color: #339933;">+</span>parts<span style="color: #009900;">&#91;</span>parts.<span style="color: #006633;">length</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">+</span>parts<span style="color: #009900;">&#91;</span>parts.<span style="color: #006633;">length</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>asc<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    criteria.<span style="color: #006633;">addOrder</span><span style="color: #009900;">&#40;</span> Order.<span style="color: #006633;">asc</span><span style="color: #009900;">&#40;</span>orderBy<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
    criteria.<span style="color: #006633;">addOrder</span><span style="color: #009900;">&#40;</span> Order.<span style="color: #006633;">desc</span><span style="color: #009900;">&#40;</span>orderBy<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Der Kode erzeugt Aliase f&#252;r alle in der orderBy vorkommenden Properties und kann auch verwendet werden, um in Criterions einen entsprechenden Pfad zu bauen.</p>
]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/hibernate-deeper-orderby.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring Hibernate Snipplets</title>
		<link>http://narcanti.keyboardsamurais.de/spring-hibernate-snipplets.html</link>
		<comments>http://narcanti.keyboardsamurais.de/spring-hibernate-snipplets.html#comments</comments>
		<pubDate>Sun, 08 Nov 2009 17:29:47 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=421</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/java-small.gif" width="25" height="40" alt="" title="Java" /><br/>Few snipplets making the usage of hibernate with annotations within spring easier.


&#60;bean name=&#34;systemProperties&#34; 
  class=&#34;org.springframework.beans.factory.config.PropertyPlaceholderConfigurer&#34; 
  lazy-init=&#34;false&#34;&#62;
  &#60;property name=&#34;location&#34; value=&#34;classpath:myproject.properties&#34;/&#62;
&#60;/bean&#62;
&#160;
&#60;bean id=&#34;dataSource&#34; class=&#34;org.apache.commons.dbcp.BasicDataSource&#34; destroy-method=&#34;close&#34;&#62;
  &#60;property name=&#34;driverClassName&#34; value=&#34;com.mysql.jdbc.Driver&#34; /&#62;
  &#60;property name=&#34;url&#34; value=&#34;${db.url}&#34; /&#62;
  &#60;property name=&#34;username&#34; value=&#34;${db.user}&#34; /&#62;
  &#60;property name=&#34;password&#34; value=&#34;${db.password}&#34; /&#62;
  &#60;property name=&#34;maxActive&#34; value=&#34;${db.maxconnections}&#34;/&#62;
  &#60;property name=&#34;maxIdle&#34; value=&#34;${db.minconnections}&#34;/&#62;
  [...]]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/java-small.gif" width="25" height="40" alt="" title="Java" /><br/><p>Few snipplets making the usage of hibernate with annotations within spring easier.<br />
<span id="more-421"></span></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;systemProperties&quot;</span> </span>
<span style="color: #009900;">  <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.beans.factory.config.PropertyPlaceholderConfigurer&quot;</span> </span>
<span style="color: #009900;">  <span style="color: #000066;">lazy-init</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;location&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;classpath:myproject.properties&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;dataSource&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.apache.commons.dbcp.BasicDataSource&quot;</span> <span style="color: #000066;">destroy-method</span>=<span style="color: #ff0000;">&quot;close&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;driverClassName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;com.mysql.jdbc.Driver&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;url&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${db.url}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;username&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${db.user}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${db.password}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;maxActive&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${db.maxconnections}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;maxIdle&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${db.minconnections}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;maxWait&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;1500&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;poolPreparedStatements&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;initialSize&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${db.minconnections}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- not explained here, but sets the default table type on create tables --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;customTableTypeMySQLInnoDBDialectInjector&quot;</span> </span>
<span style="color: #009900;">  <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.beans.factory.config.MethodInvokingFactoryBean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;staticMethod&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;de.keyboardsamurais.narcanti.common.hibernate.CustomTableTypeMySQLInnoDBDialect.setTableTypeString&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;arguments&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;DEFAULT CHARSET=utf8 COLLATE=utf8_bin&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- AnnotationSessionFactoryBean finds annotated beans in packages automaticaly --&gt;</span>	
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;sessionFactory&quot;</span> </span>
<span style="color: #009900;">  <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean&quot;</span> </span>
<span style="color: #009900;">  <span style="color: #000066;">depends-on</span>=<span style="color: #ff0000;">&quot;customTableTypeMySQLInnoDBDialectInjector&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dataSource&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;dataSource&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;annotatedPackages&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;myproject.domain&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;configurationClass&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;org.hibernate.cfg.AnnotationConfiguration&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernateProperties&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;props<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.dialect&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        de.keyboardsamurais.narcanti.common.hibernate.CustomTableTypeMySQLInnoDBDialect
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.hbm2ddl.auto&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>${db.hbm2ddl.auto}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.order_updates&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.max_fetch_depth&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.jdbc.batch_size&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>10<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.connection.useUnicode&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.connection.characterEncoding&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>utf8<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.connection.characterSetResults&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>utf8<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.connection.clobCharacterEncoding&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>utf8<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/props<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;transactionManager&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.hibernate3.HibernateTransactionManager&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;sessionFactory&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;sessionFactory&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- I preferr defining this here instead of using aspects --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;daoTransactionProxyTemplate&quot;</span> <span style="color: #000066;">abstract</span>=<span style="color: #ff0000;">&quot;true&quot;</span> </span>
<span style="color: #009900;">  <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.transaction.interceptor.TransactionProxyFactoryBean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;transactionAttributeSource&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.transaction.annotation.AnnotationTransactionAttributeSource&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;transactionManager&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;transactionManager&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- for all daos with setSessionFactory --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;daoTemplate&quot;</span> <span style="color: #000066;">abstract</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;sessionFactory&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;sessionFactory&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- example dao --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;myDao&quot;</span> <span style="color: #000066;">parent</span>=<span style="color: #ff0000;">&quot;daoTransactionProxyTemplate&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;target&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;myproject.dao.MyDaoImpl&quot;</span> <span style="color: #000066;">parent</span>=<span style="color: #ff0000;">&quot;daoTemplate&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;proxyInterfaces&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;myproject.dao.MyDao&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/spring-hibernate-snipplets.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mukke: I need you</title>
		<link>http://narcanti.keyboardsamurais.de/mukke-i-need-you.html</link>
		<comments>http://narcanti.keyboardsamurais.de/mukke-i-need-you.html#comments</comments>
		<pubDate>Sun, 01 Nov 2009 18:11:45 +0000</pubDate>
		<dc:creator>Secco</dc:creator>
				<category><![CDATA[Musik]]></category>

		<guid isPermaLink="false">http://narcanti.keyboardsamurais.de/?p=420</guid>
		<description><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/play.gif" width="24" height="24" alt="" title="Musik" /><br/>Diesmal ein etwas schnulziger Trance, den ich f&#252;r Sarah geschrieben habe.
Die Vocals stammen aus dem Lied &#8220;So in love with you&#8221; von Duke.



Download
]]></description>
			<content:encoded><![CDATA[<img src="http://narcanti.keyboardsamurais.de/images/category-icons/play.gif" width="24" height="24" alt="" title="Musik" /><br/><p>Diesmal ein etwas schnulziger Trance, den ich f&#252;r Sarah geschrieben habe.<br />
Die Vocals stammen aus dem Lied &#8220;So in love with you&#8221; von Duke.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" type="application/x-shockwave-flash" data="mp3/dewplayer.swf?son=mp3/silver+spyder+sam+-+i+need+you.mp3" width="200" height="20">
<param name="movie" value="mp3/dewplayer.swf?son=mp3/silver+spyder+sam+-+i+need+you.mp3" />
<embed src="mp3/dewplayer.swf?son=mp3/silver+spyder+sam+-+i+need+you.mp3" quality="high" width="200" height="20" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object><br />
<a href="mp3/silver spyder sam - i need you.mp3">Download</a></p>
]]></content:encoded>
			<wfw:commentRss>http://narcanti.keyboardsamurais.de/mukke-i-need-you.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
