<?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>non-random ramble &#187; hibernate</title>
	<atom:link href="http://jimbarritt.com/non-random/category/code/hibernate/feed/" rel="self" type="application/rss+xml" />
	<link>http://jimbarritt.com/non-random</link>
	<description>adventures in code</description>
	<lastBuildDate>Fri, 23 Jul 2010 13:42:14 +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>Hibernate Proxy InstantiationException</title>
		<link>http://jimbarritt.com/non-random/2010/07/23/hibernate-proxy-instantiationexception/</link>
		<comments>http://jimbarritt.com/non-random/2010/07/23/hibernate-proxy-instantiationexception/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 13:39:31 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[hibernate]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/?p=602</guid>
		<description><![CDATA[Changing entities to be lazy loaded led me to the following problem: Thanks to Kristian I jumped straight to the problem. From the Hibernate docs: Cat has a no-argument constructor. All persistent classes must have a default constructor (which can be non-public) so that Hibernate can instantiate them using Constructor.newInstance(). It is recommended that you [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jimbarritt.com/non-random/wp-content/uploads/2010/07/facade.jpg" rel="lightbox[602]"><img src="http://jimbarritt.com/non-random/wp-content/uploads/2010/07/facade.jpg" alt="" title="facade" width="500" height="375" class="aligncenter size-full wp-image-603" /></a></p>
<p>Changing entities to be lazy loaded led me to the following problem:</p>
<pre name='code' class='java:nogutter:nocontrols'>
@OneToMany(fetch = FetchType.LAZY)
</pre>
<pre name='code' class='java:nogutter:nocontrols'>
Caused by: org.hibernate.HibernateException: Javassist Enhancement failed: Thing
	at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:142)
	at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:72)
	at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:402)
	at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3483)
&#8230;.
Caused by: java.lang.InstantiationException: Thing_$$_javassist_38
	at java.lang.Class.newInstance0(Class.java:340)
	at java.lang.Class.newInstance(Class.java:308)
	at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:139)
</pre>
<p>Thanks to <a href="http://kristian-domagala.blogspot.com/2008/10/proxy-instantiation-problem-from.html">Kristian</a> I jumped straight to the problem. From the <a href="http://docs.jboss.org/hibernate/core/3.3/reference/en/html/persistent-classes.html#persistent-classes-pojo-constructor">Hibernate docs</a>:</p>
<blockquote><p>Cat has a no-argument constructor. All persistent classes must have a default constructor (which can be non-public) so that Hibernate can instantiate them using Constructor.newInstance(). It is recommended that you have a default constructor with <strong>at least</strong> package visibility for runtime proxy generation in Hibernate.</p></blockquote>
<p>This should probably read &#8220;It is essential&#8230;.&#8221;</p>
<p>Anyway now everything is real lazy so happy days.</p>
]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2010/07/23/hibernate-proxy-instantiationexception/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Log4J settings for working with Hibernate</title>
		<link>http://jimbarritt.com/non-random/2010/07/23/log4j-settings-for-working-with-hibernate/</link>
		<comments>http://jimbarritt.com/non-random/2010/07/23/log4j-settings-for-working-with-hibernate/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 12:28:37 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[hibernate]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/?p=588</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://jimbarritt.com/non-random/wp-content/uploads/2010/07/hibernate.png" rel="lightbox[588]"><img src="http://jimbarritt.com/non-random/wp-content/uploads/2010/07/hibernate.png" alt="" title="hibernate" width="600" /></a><br />
<pre name='code' class='xml:nogutter:nocontrols'>
	<!--
		These  hibernate values are quite tuned to provide a clear output of SQL and what parameters are bound
		org.hibernate should be on WARN so you don't see loads or random stuff
		org.hibernate.jdbc.ConnectionManager on DEBUG to show open and closing of connections
		org.hibernate.SQL on DEBUG to see the actual SQL statements (also need to turn it on in HibernateSessionFactory (show_sql=true)
		org.hibernate.type on TRACE	so that you can see which parameters are bound to the statements
		Any custom type mappers should also be put on trace so that you see them binding (of course you need to add the logging statements yourself)
		Please be careful when checking in this file to not check in local changes for specific debugging purposes
	-->
	<logger name="org.hibernate">
  		<level value="warn"/>
	</logger>
	<logger name="org.hibernate.jdbc.ConnectionManager">
  		<level value="debug"/>
	</logger>
	<logger name="org.hibernate.SQL">
  		<level value="debug"/>
	</logger>
	<category name="org.hibernate.type">
<priority value="trace"/>
	</category>
</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2010/07/23/log4j-settings-for-working-with-hibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hibernate components and relationships</title>
		<link>http://jimbarritt.com/non-random/2008/09/29/hibernat-components-and-relationships/</link>
		<comments>http://jimbarritt.com/non-random/2008/09/29/hibernat-components-and-relationships/#comments</comments>
		<pubDate>Mon, 29 Sep 2008 15:16:32 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[hibernate]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/2008/09/29/hibernat-components-and-relationships/</guid>
		<description><![CDATA[Situation: you have a hibernate component which itself has a link to another object (e.g. many-to-one) When loading, if hibernate is not able to satisfy the dependency, it will NOT set the field for your component. e.g. we have :]]></description>
			<content:encoded><![CDATA[<p>Situation: you have a hibernate component which itself has a link to another object (e.g. many-to-one) </p>
<p>When loading, if hibernate is not able to satisfy the dependency, it will NOT set the field for your component.</p>
<p>e.g. we have :</p>
<pre style="overflow:hidden;">
<code>
<subclass name="DraftContentPage" discriminator-value="Content" lazy="false">
    <component name="contentPage" class="ContentPage" >
        <many-to-one name="coreContent"
                            column="core_content_id"
                            unique="true"
                            not-null="false"
                            class="com.gu.r2.common.model.content.DraftContent"
                            cascade="save-update,merge"/>
    </component>
</subclass>
</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2008/09/29/hibernat-components-and-relationships/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
