<?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>H2 &#8211; My Shitty Code</title>
	<atom:link href="https://myshittycode.com/tag/h2/feed/" rel="self" type="application/rss+xml" />
	<link>https://myshittycode.com</link>
	<description>Embracing the Messiness in Search of Epic Solutions</description>
	<lastBuildDate>Fri, 06 Jan 2023 17:11:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://myshittycode.com/wp-content/uploads/2022/04/cropped-icon-32x32.png</url>
	<title>H2 &#8211; My Shitty Code</title>
	<link>https://myshittycode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">205304208</site>	<item>
		<title>Developing against H2 Database: Lesson Learned</title>
		<link>https://myshittycode.com/2014/01/09/developing-against-h2-database-lesson-learned/</link>
					<comments>https://myshittycode.com/2014/01/09/developing-against-h2-database-lesson-learned/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Thu, 09 Jan 2014 21:33:53 +0000</pubDate>
				<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[H2]]></category>
		<category><![CDATA[Hibernate]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=310</guid>

					<description><![CDATA[<p>While my production database is MS SQL Server, I have been using H2 database for rapid local development. I wrote my DDL scripts as &#8220;Transact-SQL&#8221; as possible so that I don&#8217;t need to maintain multiple DDL scripts for each database. So far, it has been working out great. My web development runs against H2&#8217;s file-based [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2014/01/09/developing-against-h2-database-lesson-learned/">Developing against H2 Database: Lesson Learned</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>While my production database is MS SQL Server, I have been using H2 database for rapid local development. I wrote my DDL scripts as &#8220;Transact-SQL&#8221; as possible so that I don&#8217;t need to maintain multiple DDL scripts for each database. So far, it has been working out great. My web development runs against H2&#8217;s file-based database because I want my data to persist until I manually wipe them off.</p>



<p>That said, I also realized that H2 does behavior a little differently from MS SQL Server. For example, I have the following Hibernate&#8217;s HQL query:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: java; title: ; notranslate">
public Collection&lt;Request&gt; getRequestsWithMatchingStatus(Collection&lt;String&gt; statusNames) {
    return sessionFactory.getCurrentSession()
            .createQuery(&quot;from Request r where r.status.name in (:statusNames)&quot;)
            .setParameterList(&quot;statusNames&quot;, statusNames)
            .list();
}
</pre></div>


<p>If <code>statusNames</code> is an empty collection, H2 will work just fine. However, MS SQL Server will throw the following exception:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
Caused by: java.sql.SQLException: Incorrect syntax near &#039;)&#039;.
	at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
	at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
	at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
</pre></div>


<p>My test cases didn&#8217;t catch this error because they run against H2&#8217;s in-memory database.</p>



<p>Of course, the fix is as easy as performing a check on the collection size first:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: java; title: ; notranslate">
public Collection&lt;Request&gt; getRequestsWithMatchingStatus(Collection&lt;String&gt; statusNames) {
    if (statusNames.isEmpty()) {
        return new ArrayList&lt;Request&gt;();
    }&lt;/code&gt;
&lt;code&gt;
&lt;/code&gt;
&lt;code&gt;    return sessionFactory.getCurrentSession()
            .createQuery(&quot;from Request r where r.status.name in (:statusNames)&quot;)
            .setParameterList(&quot;statusNames&quot;, statusNames)
            .list();
}
</pre></div>


<p>That said, H2 database allows me to do local development really fast, but I also need to make sure I test it against MS SQL Server from time to time before deploying into production.</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2014/01/09/developing-against-h2-database-lesson-learned/">Developing against H2 Database: Lesson Learned</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2014/01/09/developing-against-h2-database-lesson-learned/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">310</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Database Caching using Disk

Served from: myshittycode.com @ 2026-02-20 04:29:10 by W3 Total Cache
-->