<?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/"
	>

<channel>
	<title>Java, Programming, Struts2, jQuery, Linux and more &#187; spring</title>
	<atom:link href="http://www.jgeppert.com/category/java/spring/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jgeppert.com</link>
	<description>Johannes Geppert</description>
	<lastBuildDate>Thu, 09 Feb 2012 16:38:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Sind Java Frameworks mit Java EE 6 obsolete?</title>
		<link>http://www.jgeppert.com/2010/10/sind-java-frameworks-mit-java-ee-6-obsolete/</link>
		<comments>http://www.jgeppert.com/2010/10/sind-java-frameworks-mit-java-ee-6-obsolete/#comments</comments>
		<pubDate>Mon, 18 Oct 2010 15:09:28 +0000</pubDate>
		<dc:creator>jogep</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[struts2]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[jsf2]]></category>

		<guid isPermaLink="false">http://www.jgeppert.com/?p=442</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.jgeppert.com/2010/10/sind-java-frameworks-mit-java-ee-6-obsolete/' addthis:title='Sind Java Frameworks mit Java EE 6 obsolete? '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Matt Raible antwortet in seinem Blog auf die von Cameron McKenzie bei TheServerSide aufgestellte These "Moving from Spring to Java EE 6: The Age of Frameworks is Over" mit einem klaren nein! Interessant fand ich die Aussage das JSF1 und JSF2 meist nur von Buch Autoren, MyFaces Entwicklern oder Java EE Vendors promoted wird, aber [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.jgeppert.com/2010/10/sind-java-frameworks-mit-java-ee-6-obsolete/' addthis:title='Sind Java Frameworks mit Java EE 6 obsolete? ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.jgeppert.com/2010/10/sind-java-frameworks-mit-java-ee-6-obsolete/' addthis:title='Sind Java Frameworks mit Java EE 6 obsolete? '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Matt Raible <a title="RE: Moving from Spring to Java EE 6: The Age of Frameworks is Over" href="http://raibledesigns.com/rd/entry/re_moving_from_spring_to">antwortet in seinem Blog</a> auf die von Cameron McKenzie bei TheServerSide aufgestellte These "<a href="http://www.theserverside.com/discussions/thread.tss?thread_id=61023">Moving from Spring to Java EE 6: The Age of Frameworks is Over</a>" mit einem klaren <strong>nein!</strong>

Interessant fand ich die Aussage das JSF1 und JSF2 meist nur von Buch Autoren, MyFaces Entwicklern oder Java EE Vendors promoted wird, aber die wenigsten Entwickler damit wirklich glücklich sind. Und lieber zu Java Frameworks wie Struts2 oder Spring MVC greifen sollten. Was ich persönlich auch bestätigen kann.<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.jgeppert.com/2010/10/sind-java-frameworks-mit-java-ee-6-obsolete/' addthis:title='Sind Java Frameworks mit Java EE 6 obsolete? ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.jgeppert.com/2010/10/sind-java-frameworks-mit-java-ee-6-obsolete/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ein Webservice mit Axis2 und Spring</title>
		<link>http://www.jgeppert.com/2009/02/webservice-mit-axis2-und-spring/</link>
		<comments>http://www.jgeppert.com/2009/02/webservice-mit-axis2-und-spring/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 18:16:42 +0000</pubDate>
		<dc:creator>jogep</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[axis2]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[webservices]]></category>
		<category><![CDATA[webservice]]></category>

		<guid isPermaLink="false">http://www.jgeppert.com/?p=165</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.jgeppert.com/2009/02/webservice-mit-axis2-und-spring/' addthis:title='Ein Webservice mit Axis2 und Spring '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Mit Axis2 ist das Erstellen von Webservices für Java Programmierer noch einfacher geworden. Mit folgendem kleinen Beispiel will ich zeigen, wie man einen Webservice programmieren kann, der von Spring ein Bean injiziert bekommt. Als Erstes erstellen wir unseren Webservice als einfache Java Klasse: package com.jgeppert.services; &#160; import com.jgeppert.dao.MyDAO; &#160; private MyDAO myDAO; &#160; public class [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.jgeppert.com/2009/02/webservice-mit-axis2-und-spring/' addthis:title='Ein Webservice mit Axis2 und Spring ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.jgeppert.com/2009/02/webservice-mit-axis2-und-spring/' addthis:title='Ein Webservice mit Axis2 und Spring '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>Mit <a href="http://ws.apache.org/axis2/">Axis2</a> ist das Erstellen von Webservices für Java Programmierer noch einfacher geworden. Mit folgendem kleinen Beispiel will ich zeigen, wie man einen Webservice programmieren kann, der von <a href="http://www.springsource.org">Spring</a> ein Bean injiziert bekommt.
</p>
<p>
Als Erstes erstellen wir unseren Webservice als einfache Java Klasse:
</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.jgeppert.services</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.jgeppert.dao.MyDAO</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> MyDAO myDAO<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyWebService
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">/* Die Funktion add() ist unsere Webservice Operation die
	 * dann mit einem Client angesprochen werden kann.
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> add<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> text<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>
			myDAO.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span>text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;insert successfully&quot;</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;">RuntimeException</span> e<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> e.<span style="color: #006633;">getMessage</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>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Mit dieser Methode injiziert uns Spring unser DAO Objekt</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> setMyDAO<span style="color: #009900;">&#40;</span>MyDAO myDAO<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;">myDAO</span> <span style="color: #339933;">=</span> myDAO<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>



<p>
Als Zweites brauchen wir für Aris2 eine service.xml mit folgendem Inhalt:
</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;service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My First WebService<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ServiceClass&quot;</span> <span style="color: #000066;">locked</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		com.jgeppert.services.MyWebService
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/parameter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ServiceObjectSupplier&quot;</span> <span style="color: #000066;">locked</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/parameter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SpringBeanName&quot;</span> <span style="color: #000066;">locked</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>myWebService<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/parameter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;add&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;messageReceiver</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.apache.axis2.rpc.receivers.RPCMessageReceiver&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/operation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>



<p>
Für Spring sind die zwei Parameter <strong>ServiceObjectSupplier</strong> und <strong>SpringBeanName</strong> entscheidend, um uns das benötigte DAO zu übergeben.

Mit Hilfe eines <a href="http://ws.apache.org/axis2/1_4_1/pojoguide.html#buildpojows">Ant Scriptes</a> oder manuell kann man sich den Webservice in das für Axis2 benötigte AAR Archiv packen. Das Archiv ist im Grunde eine normale JAR Datei mit der service.xml im META-INF Verzeichnis.
</p>
<p>
Die Struktur des AAR-Archives sollte so aus sehen:
</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">-</span> MyWebService
   <span style="color: #339933;">-</span> META<span style="color: #339933;">-</span>INF
     <span style="color: #339933;">-</span> services.<span style="color: #006633;">xml</span>
   <span style="color: #339933;">-</span> com
     <span style="color: #339933;">-</span> jgeppert
       <span style="color: #339933;">-</span> services
         <span style="color: #339933;">-</span> MyWebService.<span style="color: #000000; font-weight: bold;">class</span></pre></div></div>



<p>
Damit Spring unser DAO in dem Service injizieren kann, brauchen wir noch folgenden Eintrag in unserer applicationContext.xml.</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;">id</span>=<span style="color: #ff0000;">&quot;applicationContext&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</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;myWebService&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.jgeppert.services.MyWebService&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;myDAO&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;MyDAO&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  	<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>



<p>
Nach dem deployen des AAR-Archives im services Folder der Axis2 Web Application steht der Service nun zur Verfügung.
</p><div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.jgeppert.com/2009/02/webservice-mit-axis2-und-spring/' addthis:title='Ein Webservice mit Axis2 und Spring ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.jgeppert.com/2009/02/webservice-mit-axis2-und-spring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>In Hibernate mit OneToMany Beziehungen arbeiten</title>
		<link>http://www.jgeppert.com/2008/07/in-hibernate-mit-onetomany-beziehungen-arbeiten/</link>
		<comments>http://www.jgeppert.com/2008/07/in-hibernate-mit-onetomany-beziehungen-arbeiten/#comments</comments>
		<pubDate>Mon, 28 Jul 2008 09:01:40 +0000</pubDate>
		<dc:creator>jogep</dc:creator>
				<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[annotions]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[hql]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[persistence]]></category>
		<category><![CDATA[set]]></category>
		<category><![CDATA[size]]></category>

		<guid isPermaLink="false">http://www.jgeppert.com/?p=134</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.jgeppert.com/2008/07/in-hibernate-mit-onetomany-beziehungen-arbeiten/' addthis:title='In Hibernate mit OneToMany Beziehungen arbeiten '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Bei einer Java Anwendung die mit Hibernate oder JPA als Persistence Framework arbeitet, kann es vorkommen das man alle Objekte mit HQL ermitteln will deren OneToMany Beziehungen eine bestimmte Größe haben oder mehr als null Elemente beinhalten. Eine Beispiel Definition unserer Klassen könnte in etwa so aussehen. MyObject: @Entity @Table&#40;name = &#34;my_object&#34;, schema = &#34;public&#34;&#41; [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.jgeppert.com/2008/07/in-hibernate-mit-onetomany-beziehungen-arbeiten/' addthis:title='In Hibernate mit OneToMany Beziehungen arbeiten ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.jgeppert.com/2008/07/in-hibernate-mit-onetomany-beziehungen-arbeiten/' addthis:title='In Hibernate mit OneToMany Beziehungen arbeiten '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Bei einer Java Anwendung die mit Hibernate oder JPA als Persistence Framework arbeitet, kann es vorkommen das man alle Objekte mit HQL ermitteln will deren OneToMany Beziehungen eine bestimmte Größe haben oder mehr als null Elemente beinhalten.

Eine Beispiel Definition unserer Klassen könnte in etwa so aussehen.
MyObject:


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@<span style="color: #003399;">Entity</span>
@Table<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;my_object&quot;</span>, schema <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;public&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyObject <span style="color: #000000; font-weight: bold;">implements</span> java.<span style="color: #006633;">io</span>.<span style="color: #003399;">Serializable</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">private</span> Set<span style="color: #339933;">&lt;</span>mysubobject<span style="color: #339933;">&gt;</span>  subObjects <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashSet<span style="color: #339933;">&lt;/</span>mysubobject<span style="color: #339933;">&gt;&lt;</span>mysubobject<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  @OneToMany<span style="color: #009900;">&#40;</span>cascade <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> CascadeType.<span style="color: #006633;">ALL</span> <span style="color: #009900;">&#125;</span>, fetch <span style="color: #339933;">=</span> FetchType.<span style="color: #006633;">LAZY</span>, mappedBy <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;myobject&quot;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">public</span> Set<span style="color: #339933;">&lt;/</span>mysubobject<span style="color: #339933;">&gt;&lt;</span>mysubobject<span style="color: #339933;">&gt;</span> getSubObjects<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> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">subObjects</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>mysubobject<span style="color: #339933;">&gt;</span></pre></div></div>



MySubObject:


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@<span style="color: #003399;">Entity</span>
@Table<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;my_sub_object&quot;</span>, schema <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;public&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MySubObject <span style="color: #000000; font-weight: bold;">implements</span> java.<span style="color: #006633;">io</span>.<span style="color: #003399;">Serializable</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">private</span> MyObject myObject<span style="color: #339933;">;</span>
&nbsp;
  @ManyToOne<span style="color: #009900;">&#40;</span>cascade <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>, fetch <span style="color: #339933;">=</span> FetchType.<span style="color: #006633;">LAZY</span><span style="color: #009900;">&#41;</span>
  @JoinColumn<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;myobject&quot;</span>, unique <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">public</span> MyObject getMyObject<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> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">myObject</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>



Nach dem wir unsere Klassen mit Annotations oder auch XML definiert haben können wir jetzt in unserem DAO Objekt mit folgenden HQL Befehl alle Objekte von der Datenbank anfordern die mindestens ein Element im Set subObjects haben.


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>myobject<span style="color: #339933;">&gt;</span> findAllWithElements<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;">try</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">String</span> queryString <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select model from MyObject model where size(subObjects ) &gt; 0&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">return</span> getHibernateTemplate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span>queryString<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;">RuntimeException</span> re<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;find all with elements failed&quot;</span>, re<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">throw</span> re<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>myobject<span style="color: #339933;">&gt;</span></pre></div></div>


<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.jgeppert.com/2008/07/in-hibernate-mit-onetomany-beziehungen-arbeiten/' addthis:title='In Hibernate mit OneToMany Beziehungen arbeiten ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.jgeppert.com/2008/07/in-hibernate-mit-onetomany-beziehungen-arbeiten/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mit dem Spring Framework einen Scheduler ausführen</title>
		<link>http://www.jgeppert.com/2008/07/mit-dem-spring-framework-einen-scheduler-ausfuhren/</link>
		<comments>http://www.jgeppert.com/2008/07/mit-dem-spring-framework-einen-scheduler-ausfuhren/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 09:35:25 +0000</pubDate>
		<dc:creator>jogep</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[quartz]]></category>
		<category><![CDATA[scheduler]]></category>
		<category><![CDATA[springframework]]></category>
		<category><![CDATA[timertask]]></category>

		<guid isPermaLink="false">http://www.jgeppert.com/?p=125</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.jgeppert.com/2008/07/mit-dem-spring-framework-einen-scheduler-ausfuhren/' addthis:title='Mit dem Spring Framework einen Scheduler ausführen '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Spring bietet uns die Möglichkeit, wiederkehrende Aufgaben auszuführen. Die einfachste Variante einen Scheduler zu implementieren, die ich hier zeigen werde, ist das Ausführen eines TimerTask. Dazu implementiert man als erstes eine Klasse die von TimerTask ableitet. In der Methode run() können wir jetzt unseren Code ausführen. In diesem Beispiel lassen wir uns von Spring gleich [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.jgeppert.com/2008/07/mit-dem-spring-framework-einen-scheduler-ausfuhren/' addthis:title='Mit dem Spring Framework einen Scheduler ausführen ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.jgeppert.com/2008/07/mit-dem-spring-framework-einen-scheduler-ausfuhren/' addthis:title='Mit dem Spring Framework einen Scheduler ausführen '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><a href="http://www.springframework.org/">Spring</a> bietet uns die Möglichkeit, wiederkehrende Aufgaben auszuführen. Die einfachste Variante einen Scheduler zu implementieren, die ich hier zeigen werde, ist das Ausführen eines <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/TimerTask.html">TimerTask</a>.

Dazu implementiert man als erstes eine Klasse die von <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/TimerTask.html">TimerTask</a> ableitet. In der Methode <em>run()</em> können wir jetzt unseren Code ausführen. In diesem Beispiel lassen wir uns von <a href="http://www.springframework.org/">Spring</a> gleich noch ein DAO Objekt übergeben mit dem wir eine Datenbank Operation ausführen können.


<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> MyTimerTask <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399;">TimerTask</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Log log <span style="color: #339933;">=</span> LogFactory.<span style="color: #006633;">getLog</span><span style="color: #009900;">&#40;</span>MyTimerTask.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> MeinDAO meinDAO<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		log.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Starte MyTimerTask &quot;</span><span style="color: #339933;">+</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</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: #666666; font-style: italic;">// Etwas sinnvolles machen!</span>
		meinDAO.<span style="color: #006633;">deleteAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		log.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Beende MyTimerTask &quot;</span><span style="color: #339933;">+</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</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: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setMeinDAO<span style="color: #009900;">&#40;</span>MeinDAO meinDAO<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;">meinDAO</span> <span style="color: #339933;">=</span> meinDAO<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>




Jetzt müssen wir nur noch unsere <em>applicationContext.xml</em> um folgende Einträge erweitern.


<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;">id</span>=<span style="color: #ff0000;">&quot;myTimerTask&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.jgeppert.timer.MyTimerTask&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;meinDAO&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;MeinDAO&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;scheduledTask&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.scheduling.timer.ScheduledTimerTask&quot;</span> <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: #808080; font-style: italic;">&lt;!-- Die Startzeit nach der der TimerTask initial starten soll in Millisekunden --&gt;</span>
		<span style="color: #808080; font-style: italic;">&lt;!-- In diesem Beispiel also nach einer Minute --&gt;</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;delay&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;60000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
		<span style="color: #808080; font-style: italic;">&lt;!-- Alle wieviel Millisekunden solle der Task wieder laufen --&gt;</span>
		<span style="color: #808080; font-style: italic;">&lt;!-- In diesem Beispiel läuft der Task alle 10 Minuten --&gt;</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;period&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;600000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
		<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;timerTask&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;myTimerTask&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;timerFactory&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.scheduling.timer.TimerFactoryBean&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;scheduledTimerTasks&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	       		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ref</span> <span style="color: #000066;">bean</span>=<span style="color: #ff0000;">&quot;scheduledTask&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list<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></pre></div></div>




So lässt sich also auf einfache Art und Weise ein Timer mit <a href="http://www.springframework.org/">Spring</a> ausführen. Mehr Informationen und komplexere Beispiele mit dem Quartz Scheduler findet ihr in der <a href="http://static.springframework.org/spring/docs/2.5.5/reference/scheduling.html">Dokumentation</a>.<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.jgeppert.com/2008/07/mit-dem-spring-framework-einen-scheduler-ausfuhren/' addthis:title='Mit dem Spring Framework einen Scheduler ausführen ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.jgeppert.com/2008/07/mit-dem-spring-framework-einen-scheduler-ausfuhren/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

