<?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>Pink Sandbox &#187; Hibernate</title>
	<atom:link href="http://www.pink-sandbox.com/tag/hibernate/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pink-sandbox.com</link>
	<description></description>
	<lastBuildDate>Fri, 16 Apr 2010 08:17:28 +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>Changing Hibernate Mapping from XML to Annotations</title>
		<link>http://www.pink-sandbox.com/technology/changing-hibernate-mapping-from-xml-to-annotation/</link>
		<comments>http://www.pink-sandbox.com/technology/changing-hibernate-mapping-from-xml-to-annotation/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 02:51:56 +0000</pubDate>
		<dc:creator>kelay</dc:creator>
				<category><![CDATA[Geekology]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Hibernate Annotations]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.pink-sandbox.com/?p=126</guid>
		<description><![CDATA[It was because of my job interview last Friday that I&#8217;ve decided to start doing away with mapping my hibernate metadata on xml and go for Annotations instead. The interviewer suggested it and of course I&#8217;m easily convinced once I heard that &#8220;it make things easier.&#8221;
The great thing about these frameworks is that everything&#8217;s utterly [...]]]></description>
			<content:encoded><![CDATA[<p>It was because of my job interview last Friday that I&#8217;ve decided to start doing away with mapping my hibernate metadata on xml and go for Annotations instead. The interviewer suggested it and of course I&#8217;m easily convinced once I heard that &#8220;it make things easier.&#8221;</p>
<p><span id="more-126"></span>The great thing about these frameworks is that everything&#8217;s utterly comprehensive and modular. You just need to identify one specific thing that you&#8217;d want to integrate and just work on it bit by bit. Learning these web frameworks rattled me in the beginning with its steep learning curve but once you get the hang of it, integrating any modules that you can think of gets easier and easier. Also, you can never really run out of online tutorials and resources to guide you through the integration; forums almost always have already discussed the programming issues that you&#8217;re encountering, you just need to know how to search for it.</p>
<p>So, right now, I am already working on this long, long running project with some objects already mapped. I picked one object to try to convert from xml mapping to Annotations mapping &#8211; Project. Hibernate already have a road map (http://hibernate.org/152.html) defined in case you wanted to learn a specific module.</p>
<p>So firstly, I downloaded Hibernate Annotations and all its dependencies. Then made sure that it&#8217;s in my classpath.</p>
<p>Then I changed this</p>
<pre name="code" class="xml"><?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.pink.sandbox.pts.domain.Project" table="project" >
        <id name="id">
            <generator class="increment"></generator>
        </id>
<property name="name"></property>
<property name="joNum"></property>
<property name="poNum"></property>
<property name="description"></property>
        <many-to-one name="department" class="com.pink.sandbox.hris.domain.Department"></many-to-one>
        <many-to-one name="client" class="com.pink.sandbox.cms.domain.Client" lazy="false"></many-to-one>
<property name="startDate" type="timestamp"></property><!-- Production Start Date -->
<property name="endDate" type="timestamp"></property><!-- Production End Date -->
<property name="clientStartDate" type="timestamp"></property>
<property name="clientEndDate" type="timestamp"></property>
<property name="completed" type="boolean"></property>
<list name="stages">
            <key column="projectId"></key>
<list-index column="seqIdx"></list-index>
            <one-to-many class="com.pink.sandbox.pts.domain.Stage"></one-to-many>
        </list>
    </class>
</hibernate-mapping></pre>
<p>into this</p>
<pre name="code" class="java">package com.pink.sandbox.pts.domain;

import org.hibernate.annotations.*;
import javax.persistence.*;

import java.util.Date;
import java.util.List;

import com.pink.sandbox.cms.domain.Client;
import com.pink.sandbox.hris.domain.Department;

@javax.persistence.Entity
@javax.persistence.Table(name="project")
public class Project {
    @Id @GeneratedValue(generator="generator")
    @GenericGenerator(name = "generator", strategy = "increment")
    private Long id;

    private String name;

    @ManyToOne
    @JoinColumn(name="department")
    private Department department;
    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="client")
    private Client client;

    private String joNum;
    private String description;

    private Date startDate;
    private Date endDate;

    private String poNum;

    private Date clientStartDate;
    private Date clientEndDate;

    @OneToMany(cascade = javax.persistence.CascadeType.ALL)
    @IndexColumn(name = "seqIdx")
    @JoinColumn(name="parentId")
    private List stages;

    private boolean completed;
    /* getter and setter methods go here ...*/
}</pre>
<p>and change a few lines in my hibernate.cfg.xml from this</p>
<pre name="code" class="xml:nogutter:nocontrols">
<mapping resource="com/pink/sandbox/pts/domain/Project.hbm.xml" /></pre>
<p>into this</p>
<pre name="code" class="xml:nogutter:nocontrols">
<mapping class="com.pink.sandbox.pts.domain.Project" /></pre>
<p>and then add this into my session factory bean</p>
<pre name="code" class="xml:nogutter:nocontrols">
<property name="configurationClass">
        <value>org.hibernate.cfg.AnnotationConfiguration</value>
    </property></pre>
<p> <img src='http://www.pink-sandbox.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pink-sandbox.com/technology/changing-hibernate-mapping-from-xml-to-annotation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Value &#8216;0000-00-00&#8242; can not be represented as java.sql.Timestamp</title>
		<link>http://www.pink-sandbox.com/technology/value-0000-00-00-can-not-be-represented-as-javasqltimestamp/</link>
		<comments>http://www.pink-sandbox.com/technology/value-0000-00-00-can-not-be-represented-as-javasqltimestamp/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 05:36:00 +0000</pubDate>
		<dc:creator>kelay</dc:creator>
				<category><![CDATA[Geekology]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.pink-sandbox.com/?p=21</guid>
		<description><![CDATA[I&#8217;ve been googling for an easy workaround to a org.hibernate.exception.GenericJDBCException: Value &#8216;0000-00-00&#8242; can not be represented as java.sql.Timestamp. Changing the zero-dates to null is not actually an option because it might break the (poorly developed) application already using the database. This application I am working would just want to query a few reports from it. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been googling for an easy workaround to a <span style="font-weight: bold;">org.hibernate.exception.GenericJDBCException: Value &#8216;0000-00-00&#8242; can not be represented as java.sql.Timestamp</span>. Changing the zero-dates to null is not actually an option because it might break the (poorly developed) application already using the database. This application I am working would just want to query a few reports from it. So&#8230;</p>
<p>Finally, I was able to stumble onto a straightforward solution to the <a href="http://no-tes.blogspot.com/2006/12/value-0000-00-00-can-not-be.html">Value &#8216;0000-00-00&#8242; can not be represented as java.sql.Timestamp</a> exception:</p>
<ul>
<li>It is <span style="font-weight: bold;">a MySQL specific error</span>.</li>
<li>You just need to add <span style="font-weight: bold;">?zeroDateTimeBehavior=convertToNull</span> to your connection string (<span style="font-style: italic;">jdbc:mysql://myhost/mydatabase?zeroDateTimeBehavior=convertToNull</span>)</li>
</ul>
<p>So thank you! <img src='http://www.pink-sandbox.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pink-sandbox.com/technology/value-0000-00-00-can-not-be-represented-as-javasqltimestamp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
