<?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>ifNotNull</title>
	<atom:link href="http://www.ifnotnull.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ifnotnull.com</link>
	<description></description>
	<lastBuildDate>Wed, 02 May 2012 12:11:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Hibernate &amp; Generics; YourObject has an unbound type and no explicit target entity</title>
		<link>http://www.ifnotnull.com/2012/04/25/hibernate-yourobject-has-an-unbound-type-and-no-explicit-target-entity/</link>
		<comments>http://www.ifnotnull.com/2012/04/25/hibernate-yourobject-has-an-unbound-type-and-no-explicit-target-entity/#comments</comments>
		<pubDate>Wed, 25 Apr 2012 15:50:43 +0000</pubDate>
		<dc:creator>scott</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.ifnotnull.com/?p=50</guid>
		<description><![CDATA[Just worked my way through a brain fart regarding how Hibernate plays with Generics. I was having a terrible time with have mapped generic objects in Hibernate. MyObject defined a hierarchy, where you could retrieve either it&#8217;s children, or it&#8217;s &#8230; <a href="http://www.ifnotnull.com/2012/04/25/hibernate-yourobject-has-an-unbound-type-and-no-explicit-target-entity/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just worked my way through a brain fart regarding how Hibernate plays with Generics.</p>
<p>I was having a terrible time with have mapped generic objects in Hibernate. MyObject defined a hierarchy, where you could retrieve either it&#8217;s children, or it&#8217;s parent. Something along the lines of:<br />
<code><br />
@Entity<br />
@Table(name = "MY_OBJECT")<br />
@Inheritance(strategy = InheritanceType.JOINED)<br />
@DiscriminatorColumn(name = "MY_OBJECT_DISCRIMINATOR_COLUMN")<br />
public abstract class MyObject&lt;P extends MyObject&lt;?, ?&gt;, C extends MyObject&lt;?, ?&gt;&gt; implements Serializable {<br />
	@Id<br />
	@Column(name = "ID")<br />
	private String id;</p>
<p>	@ManyToOne(targetEntity=MyObject.class)<br />
	@JoinColumn<br />
	private P parent;</p>
<p>	@OneToMany(mappedBy = "parent", cascade = CascadeType.PERSIST)<br />
	private List<C> children;</p>
<p>	//Getters and Setters<br />
}<br />
</code></p>
<p>Looks all fine and dandy from here, right? Executing anything involving this would give me a terrible stack trace, completely blowing up my Spring context, and ending in:<br />
<code><br />
Caused by: org.hibernate.AnnotationException: Property MyObject.children has an unbound type and no explicit target entity. Resolve this Generic usage issue or set an explicit target attribute (eg @OneToMany(target=) or use an explicit @Type<br />
	at org.hibernate.cfg.PropertyContainer.assertTypesAreResolvable(PropertyContainer.java:136)<br />
	at org.hibernate.cfg.PropertyContainer.getProperties(PropertyContainer.java:114)<br />
	at org.hibernate.cfg.AnnotationBinder.addElementsOfClass(AnnotationBinder.java:1384)<br />
	at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:235)<br />
	at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:686)<br />
	at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3977)<br />
	at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3931)<br />
	at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1368)<br />
	at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1345)<br />
	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717)<br />
	at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)<br />
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)<br />
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)<br />
	... 58 more<br />
</code></p>
<p>I thought, I don&#8217;t want to explicitly define a type, that&#8217;s why I&#8217;m using Generics! What slipped my mind was type erasure. By the time this code got executed, it had completely forgotten about the P and C for parent and children, and wouldn&#8217;t know that they types extend MyObject. In the end, I realized that it wasn&#8217;t asking for the concrete type for the target in OneToMany, and the abstract type would be fine. In the end, the fix was super simple, and I felt a little embarrassed. The modified code is as follows:<br />
<code><br />
@ManyToOne(targetEntity=Content.class)<br />
	@JoinColumn(name = "PARENT_CONTENT_ID")<br />
	@JsonIgnore<br />
	private P parent;</p>
<p>	@OneToMany(mappedBy = "parent", cascade = CascadeType.PERSIST, targetEntity=Content.class)<br />
	@JsonIgnore<br />
	private List&lt;C&gt; children;<br />
</code></p>
<p>I&#8217;ll get you next time Type Erasure!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ifnotnull.com/2012/04/25/hibernate-yourobject-has-an-unbound-type-and-no-explicit-target-entity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up additional Maven Repositories</title>
		<link>http://www.ifnotnull.com/2011/12/03/setting-up-additional-maven-repositories/</link>
		<comments>http://www.ifnotnull.com/2011/12/03/setting-up-additional-maven-repositories/#comments</comments>
		<pubDate>Sat, 03 Dec 2011 23:34:58 +0000</pubDate>
		<dc:creator>scott</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.ifnotnull.com/?p=28</guid>
		<description><![CDATA[This is something that I&#8217;ve done before, but forgot to document, and had to look it up again when setting up my home computer for some development with Maven. The Maven Central Repo may or may not contain all the &#8230; <a href="http://www.ifnotnull.com/2011/12/03/setting-up-additional-maven-repositories/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is something that I&#8217;ve done before, but forgot to document, and had to look it up again when setting up my home computer for some development with Maven.</p>
<p>The Maven Central Repo may or may not contain all the libraries you need when building. Common missing libraries may include:</p>
<ul>
<li>com.sun.jdmk:jmxtools:jar:1.2.1</li>
<li>com.sun.jmx:jmxri:jar:1.2.1</li>
<li>javax.jms:jms:jar:1.1</li>
</ul>
<p>A quick way to fix this up is to add some more repositories to Maven.</p>
<p>You can add the repositories to either your project POM, your user settings.xml, or global settings.xml</p>
<pre class="brush: xml; gutter: true">&lt;profile&gt;
  &lt;id&gt;extra-repos&lt;/id&gt;
  &lt;repositories&gt;
    &lt;repository&gt;
      &lt;id&gt;jboss-repository&lt;/id&gt;
      &lt;name&gt;JBoss Deprecated Maven Repository&lt;/name&gt;
      &lt;url&gt;https://repository.jboss.org/nexus/content/groups/public&lt;/url&gt;
      &lt;layout&gt;default&lt;/layout&gt;
      &lt;releases&gt;&lt;enabled&gt;true&lt;/enabled&gt;&lt;updatePolicy&gt;never&lt;/updatePolicy&gt;&lt;/releases&gt;
      &lt;snapshots&gt;&lt;enabled&gt;false&lt;/enabled&gt;&lt;updatePolicy&gt;never&lt;/updatePolicy&gt;&lt;/snapshots&gt;
    &lt;/repository&gt;
    &lt;repository&gt;
      &lt;id&gt;maven2-repository.dev.java.net&lt;/id&gt;
      &lt;name&gt;Java.net Repository for Maven&lt;/name&gt;
      &lt;url&gt;http://download.java.net/maven/2/&lt;/url&gt;
      &lt;layout&gt;default&lt;/layout&gt;
    &lt;/repository&gt;
    &lt;repository&gt;
      &lt;id&gt;maven2-repository.dev.java.net&lt;/id&gt;
      &lt;name&gt;Java.net Repository for Maven&lt;/name&gt;
      &lt;url&gt;https://repository.jboss.org/&lt;/url&gt;
      &lt;layout&gt;default&lt;/layout&gt;
    &lt;/repository&gt;
  &lt;/repositories&gt;
&lt;/profile&gt;</pre>
<p>After that, you can make sure this profile is always enabled by also adding it to your active profiles in your settings.xml</p>
<pre class="brush: xml; gutter: true">  &lt;activeProfiles&gt;
    &lt;activeProfile&gt;extra-repos&lt;/activeProfile&gt;
  &lt;/activeProfiles&gt;</pre>
<p>Once you&#8217;ve added these additional repositories, you might also have to manually install some libraries. I ran into this problem with jmxtools.jar 1.2.1 and jmxri.jar 1.2.1. <a href="http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-java-plat-419418.html" target="_blank">These have to be downloaded from Oracle</a>; the jmx libraries I was looking for were found under jmx 1.2.1.</p>
<p>After downloading the libraries, you simply have to install them to your own repository. If you&#8217;re just using a local repository, it&#8217;s as simple as</p>
<pre class="brush: bash; gutter: true">mvn install:install-file -Dfile=jmxri.jar -DgroupId=com.sun.jmx -DartifactId=jmxri -Dversion=1.2.1 -Dpackaging=jar
mvn install:install-file -Dfile=jmxtools.jar -DgroupId=com.sun.jdmk -DartifactId=jmxtools -Dversion=1.2.1 -Dpackaging=jar</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ifnotnull.com/2011/12/03/setting-up-additional-maven-repositories/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

