<?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>Cake Solutions Team Blog &#187; HqlToken</title>
	<atom:link href="http://www.cakesolutions.net/teamblogs/tag/hqltoken/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cakesolutions.net/teamblogs</link>
	<description>void magic() { }</description>
	<lastBuildDate>Tue, 07 Feb 2012 12:02:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>HqlToken exception in dm Server</title>
		<link>http://www.cakesolutions.net/teamblogs/2010/02/21/hqltoken-exception-in-dm-server/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hqltoken-exception-in-dm-server</link>
		<comments>http://www.cakesolutions.net/teamblogs/2010/02/21/hqltoken-exception-in-dm-server/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 19:17:41 +0000</pubDate>
		<dc:creator>Jan Machacek</dc:creator>
				<category><![CDATA[Jan's Blog]]></category>
		<category><![CDATA["ClassCastException HqlToken"]]></category>
		<category><![CDATA['ClassCastException HqlToken OSGi']]></category>
		<category><![CDATA[dm Server]]></category>
		<category><![CDATA[HqlToken]]></category>
		<category><![CDATA[OSGi]]></category>

		<guid isPermaLink="false">http://www.cakesolutions.net/teamblogs/?p=503</guid>
		<description><![CDATA[If you&#8217;re using Hibernate in WebLogic, some of you may have come across a class loading problem, because WebLogic includes Antlr 2.7 on its main classpath, and when you start application that requires antlr as well, you will end up &#8230; <a href="http://www.cakesolutions.net/teamblogs/2010/02/21/hqltoken-exception-in-dm-server/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using Hibernate in WebLogic, some of you may have come across a class loading problem, because WebLogic includes Antlr 2.7 on its main classpath, and when you start application that requires antlr as well, you will end up with strange class loading and casting exceptions.<br />
OSGi should really solve all this, shouldn&#8217;t it? We no longer have monolithic classpaths, we have bundles with isolated classpaths and the OSGi runtime provides the lifecycle management and dependency resolution services. Well, in case of Hibernate, it is not that simple. Let&#8217;s say you have a typical web application with the <i>repository</i> tier implemented in Hibernate. The bundlified Hibernate distribution (courtesy of the <a href="http://www.springsource.com/repository/app">SpringSource Enterprise Bundle Repository</a>) correctly depends on Antlr 2.7; and so&#8211;to satisfy the dependency&#8211;you make your <i>repository</i> bundle depend on the appropriate Antlr bundle, and all seems to be working. Until you use more complex HQL query; that is one that does not begin with <code>select</code>, but with <code>delete</code> or <code>update</code>.<br />
You see, Hibernate uses Antlr to translate the HQL into an abstract syntax tree. The root of the problem is that it [Hibernate] passes a name of its internal class to Antlr. Antlr then tries to load the class using the provided name and use this class in the vertices of the AST. Naturally, in OSGi, this is a problem, because the Antlr bundle does not depend on Hibernate. The error message is then quite obvious <code>ClassNotFoundException: HqlToken</code>, but this exception is thrown from Antlr rather than from Hibernate or the rest your application.<br />
The dm Server&#8217;s extensions to the OSGi standard allow us to specify PAR-wide resolution context, which solves this problem.<br />
In practice, you have to place both your <i>repository</i> and <i>webapp</i> bundles in a PAR; in your <i>repository</i>&#8216;s <code>MANIFEST.MF</code>, you need to specify</p>
<pre>
...
Import-Bundle: ...,
 com.springsource.org.hibernate;version="[3.3.1.GA,3.3.1.GA]";
 <b>import-scope:=application</b>,
...
</pre>
<p>and finally, in your <i>webapp</i>, you need to include dependency on Hibernate in its <code>MANIFEST.MF</code>.<br />
In summary, you need to:</p>
<ul>
<li>Mark the Hibernate <code>Import-Bundle</code> entry with <code>import-scope:=application</code> in <i>repository</i>,</li>
<li>Include Hibernate in <code>Import-Bundle</code> in <i>webapp</i></li>
</ul>
<p>These two simple steps solve the <br /><code>ClassNotFoundException: org.hibernate.hql.ast.HqlToken</code> web applications that use Hibernate in dm Server 2.0.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cakesolutions.net/teamblogs/2010/02/21/hqltoken-exception-in-dm-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

