<?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>Shaun Abram &#187; Hibernate</title>
	<atom:link href="http://www.shaunabram.com/tag/hibernate/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shaunabram.com</link>
	<description>Java and Technology weblog</description>
	<lastBuildDate>Tue, 27 Jul 2010 23:14:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Running Hibernate unit tests with Maven</title>
		<link>http://www.shaunabram.com/hibernate-maven-unit-tests/</link>
		<comments>http://www.shaunabram.com/hibernate-maven-unit-tests/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 08:37:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Maven]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=42</guid>
		<description><![CDATA[I recently converted a project I have been working on to use Maven. After setting up all the dependencies in the pom, I got everything compiling fine but ran into problems getting the unit tests to pick up the hibernate config (hibernate.cfg.xml) and hibernate mapping (*.hbm.xml) files. With hindsight, it is straightforward, but it took [...]]]></description>
			<content:encoded><![CDATA[<p>I recently converted a project I have been working on to use <a href="http://maven.apache.org/">Maven</a>. After setting up all the dependencies in the pom, I got everything compiling fine but ran into problems getting the unit tests to pick up the hibernate config (hibernate.cfg.xml) and hibernate mapping (*.hbm.xml) files. With hindsight, it is straightforward, but it took me a while to figure it out so I thought I&#8217;d post the solution here.</p>
<p>Initially, I had my hibernate.cfg.xml file in the following directory</p>
<p style="padding-left: 30px;">my-app/src/main/java</p>
<p>And when I first tried to run my hibernate unit tests (mvn test), I got this error:</p>
<p style="padding-left: 30px;">SessionFactory creation failed.org.hibernate.HibernateException: /hibernate.cfg.xml not found</p>
<p>Some checking of the maven docs and some forums revealed the following possible solutions:<br />
1) Copy the hibernate.cfg.xml file to</p>
<p style="padding-left: 30px;">my-app/target/classes</p>
<p>This works, however I think it is a hack as the target folder is generated rather than being somewhere you should actually manually create files.<br />
2) The next solution I found suggested moving the hibernate.cfg.xml to</p>
<p style="padding-left: 30px;">my-app/src/main/resources</p>
<p>This works well as the contents of this folder are copied to the base level of the my-app/target/classes folder so it is basically a &#8216;more correct&#8217; solution than the first.<br />
3) The next and I think best solution was to create a new, duplicate hibernate.cfg.xml inside</p>
<p style="padding-left: 30px;">my-app/src/test/resources</p>
<p>This allows a different hibernate.cfg.xml file to be used for testing and, for example, facilitates connecting to a different database (such as <a href="http://hsqldb.org/">hsqldb</a>) for testing while continuing to use your regular database (such as <a href="http://www.mysql.com/">MySQL</a>) for the app itself.</p>
<p>A couple of points to note:</p>
<p>1) The hibernate mapping files (i.e. the *.hbm.xml files) should also be in the resources folder (in whatever directory structure you choose) to ensure that these too are accessible by the unit tests.</p>
<p>2) I am not (yet) using Spring with the hibernate components, which would likely have changed the above setup.</p>
<p>Refs/links</p>
<p style="padding-left: 30px;"><a href="http://maven.apache.org/guides/getting-started/index.html#How_do_I_add_resources_to_my_JAR">http://maven.apache.org/guides/getting-started/index.html#How_do_I_add_resources_to_my_JAR</a></p>
<p style="padding-left: 30px;"><a href="http://www.mail-archive.com/users@maven.apache.org/msg54720.html">http://www.mail-archive.com/users@maven.apache.org/msg54720.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/hibernate-maven-unit-tests/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Persisting Money class with Hibernate</title>
		<link>http://www.shaunabram.com/persisting-money-class-with-hibernate/</link>
		<comments>http://www.shaunabram.com/persisting-money-class-with-hibernate/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 05:09:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[money]]></category>
		<category><![CDATA[timeandmoney]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=39</guid>
		<description><![CDATA[Further to my previous post about representing monetary amounts in Java, I have been using the TimeAndMoney library. I ran into some problems persisting my classes that use Money via Hibernate. I should point out that these are not problems with the Money class or the timeandmoney library, rather than with my hibernate setup, but [...]]]></description>
			<content:encoded><![CDATA[<p>Further to my <a href="http://www.shaunabram.com/?p=37">previous post</a> about representing monetary amounts in Java, I have been using the <a href="http://timeandmoney.sourceforge.net/">TimeAndMoney</a> library.</p>
<p>I ran into some problems persisting my classes that use Money via <a href="http://www.hibernate.org/">Hibernate</a>. I should point out that these are not problems with the Money class or the timeandmoney library, rather than with my hibernate setup, but I thought I would post my approach here for future reference.</p>
<p>I started by incorrectly trying to map my Money field (in my case, called &#8216;openingBalance) as a property, viz:</p>
<p style="padding-left: 30px;">&lt;property name=&#8221;openingBalance&#8221; type=&#8221;com.domainlanguage.money.Money&#8221;&gt;</p>
<p>Which resulted in the following error:</p>
<p style="padding-left: 30px;">SEVERE: Data truncation: Data too long for column &#8216;openingBalance&#8217; at row 1<br />
Exception in thread &#8220;main&#8221; org.hibernate.exception.GenericJDBCException: could not insert&#8230;</p>
<p>Then I tried mapping it as a component, viz</p>
<p style="padding-left: 30px;">&lt;component name=&#8221;openingBalance&#8221; class=&#8221;com.domainlanguage.money.Money&#8221;&gt;</p>
<p style="padding-left: 60px;">&lt;property name=&#8221;amount&#8221;/&gt;</p>
<p style="padding-left: 60px;">&lt;property name=&#8221;currency&#8221;/&gt;</p>
<p style="padding-left: 30px;">&lt;/component&gt;</p>
<p>But this resulted in the following error:</p>
<p style="padding-left: 30px;">Initial SessionFactory creation failed.org.hibernate.PropertyNotFoundException: Could not find a setter for property amount in class com.domainlanguage.money.Money<br />
Exception in thread &#8220;main&#8221; java.lang.ExceptionInInitializerError</p>
<p>This is because the Money class has no setAmount or setCurrency methods. The solution is to specify field access (as opposed to accessor method access), as in</p>
<p style="padding-left: 30px;">&lt;component name=&#8221;openingBalance&#8221; class=&#8221;com.domainlanguage.money.Money&#8221;&gt;</p>
<p style="padding-left: 60px;">&lt;property access=&#8221;field&#8221; name=&#8221;amount&#8221;/&gt;</p>
<p style="padding-left: 60px;">&lt;property access=&#8221;field&#8221; name=&#8221;currency&#8221;/&gt;</p>
<p style="padding-left: 30px;">&lt;/component&gt;</p>
<p>Note that if you check the Money javadocs, it (correctly) says that the setters are not provided because they would break encapsulation They do however (and I quote, &#8220;begrudgingly&#8221;) provide alternative setters such as setForPersistentMapping_Amount, but I am not sure how to get Hibernate to use these, and in this case, I don&#8217;t think it is necessary or beneficial anyway.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/persisting-money-class-with-hibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Workflow Management: JBoss&#8217;s JBPM</title>
		<link>http://www.shaunabram.com/workflow-mnagement-jbosss-jbpm/</link>
		<comments>http://www.shaunabram.com/workflow-mnagement-jbosss-jbpm/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 06:21:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Products]]></category>
		<category><![CDATA[bpel]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[jbpm]]></category>
		<category><![CDATA[jpdl]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=21</guid>
		<description><![CDATA[The project I&#8217;m currently working on had a requirement for a workflow engine to manage the various process flow options for an order management system. For example, an order can be created, modified, submitted etc and we need to be able to persist and retrieve the process at any stage as we wait for human [...]]]></description>
			<content:encoded><![CDATA[<p>The project I&#8217;m currently working on had a requirement for a workflow engine to manage the various process flow options for an order management system. For example, an order can be created, modified, submitted etc and we need to be able to persist and retrieve the process at any stage as we wait for human involvement to move to the next stage.  I have been evaluating JBoss&#8217;s JBPM. It seems to meet our requirements but has been very difficult to get up and running. Overall it has been a frustrating process so far.  The main JBoss JBPM site is at <a href="http://www.jboss.com/products/jbpm">here</a> and theServerSide has a good article on using it with <a href="http://www.theserverside.com/tt/articles/article.tss?l=jBPMandSpring">Spring/Hibernate integration</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/workflow-mnagement-jbosss-jbpm/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
