<?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>The eflow blog &#187; hsqldb</title>
	<atom:link href="http://blog.eflow.org/archives/tag/hsqldb/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.eflow.org</link>
	<description>Insert some amazingly witty tagline here</description>
	<lastBuildDate>Fri, 23 Apr 2010 03:19:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Puzzling DBUnit Error</title>
		<link>http://blog.eflow.org/archives/65</link>
		<comments>http://blog.eflow.org/archives/65#comments</comments>
		<pubDate>Sat, 09 Aug 2008 13:36:47 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[openmrs]]></category>
		<category><![CDATA[dbunit]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[hsqldb]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://blog.eflow.org/?p=65</guid>
		<description><![CDATA[When writing a dbunit test for the CohortServiceTest, I encountered this non-informative error:
org.dbunit.dataset.NoPrimaryKeyException: COHORT_MEMBER
In the Cohort mapping file the cohort_member table is mapped like any hibernate collection:

&#60;set name="memberIds" cascade="none" lazy="true" table="cohort_member"&#62;
    &#60;key column="cohort_id" /&#62;
    &#60;element column="patient_id" type="integer" /&#62;
&#60;/set&#62;

It looks normal enough.  Cohort.memberIds is a list of integers defined by [...]]]></description>
			<content:encoded><![CDATA[<p>When writing a <a href="http://dbunit.sourceforge.net/">dbunit</a> test for the <a href="http://dev.openmrs.org/browser/openmrs/trunk/test/api/org/openmrs/test/api/CohortServiceTest.java">CohortServiceTest</a>, I encountered this non-informative error:</p>
<blockquote><p>org.dbunit.dataset.NoPrimaryKeyException: COHORT_MEMBER</p></blockquote>
<p>In the <a href="http://dev.openmrs.org/browser/openmrs/trunk/metadata/api/hibernate/org/openmrs/api/db/hibernate/Cohort.hbm.xml">Cohort</a> mapping file the cohort_member table is mapped like any hibernate collection:</p>
<blockquote>
<pre>&lt;set name="memberIds" cascade="none" lazy="true" table="cohort_member"&gt;
    &lt;key column="cohort_id" /&gt;
    &lt;element column="patient_id" type="integer" /&gt;
&lt;/set&gt;</pre>
</blockquote>
<p>It looks normal enough.  <a href="http://resources.openmrs.org/doc/org/openmrs/Cohort.html#getMemberIds()">Cohort.memberIds</a> is a list of integers defined by the cohort_member table.</p>
<p>Hibernate automatically creates the schema in our test hsqldb because we have hbm2ddl set to &#8220;auto&#8221;.  The problem arose here because hibernate wasn&#8217;t creating a dual primary key on the member_ids table.  Digging through the code, I found that Hibernate only assumes the primary keys are the columns that set to &#8220;not null&#8221;.</p>
<p>The corrected mapping with both columns set to be not-null:</p>
<blockquote>
<pre>&lt;set name="memberIds" cascade="none" lazy="true" table="cohort_member"&gt;
    &lt;key column="cohort_id" not-null="true"/&gt;
    &lt;element column="patient_id" type="integer" not-null="true"/&gt;
&lt;/set&gt;</pre>
</blockquote>
<p>Now hibernate creates the table with primary keys and hsql is happy again.</p>
 <img src="http://blog.eflow.org/wp-content/plugins/feed-statistics.php?view=1&post_id=65" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.eflow.org/archives/65/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
