<?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>The Error Message &#187; Hibernate</title>
	<atom:link href="http://www.theerrormessage.com/category/hibernate/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.theerrormessage.com</link>
	<description>Fix your error</description>
	<lastBuildDate>Tue, 13 Dec 2011 20:16:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>org.hibernate.HibernateException: identifier of an instance of members.Appointment was altered from 8 to 8</title>
		<link>http://www.theerrormessage.com/2007/08/orghibernatehibernateexception-identifier-of-an-instance-of-membersappointment-was-altered-from-8-to-8/</link>
		<comments>http://www.theerrormessage.com/2007/08/orghibernatehibernateexception-identifier-of-an-instance-of-membersappointment-was-altered-from-8-to-8/#comments</comments>
		<pubDate>Mon, 06 Aug 2007 22:14:45 +0000</pubDate>
		<dc:creator>thalissar</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.theerrormessage.com/2007/08/06/orghibernatehibernateexception-identifier-of-an-instance-of-membersappointment-was-altered-from-8-to-8/</guid>
		<description><![CDATA[Full error message: Exception occurred during event dispatching: org.hibernate.HibernateException: identifier of an instance of members.Appointment was altered from 8 to 8 at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:58) at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:157) at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:113) at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196) at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106) at members.AppointmentDialog.jButtonSaveActionPerformed(AppointmentDialog.java:279) at members.AppointmentDialog.access$000(AppointmentDialog.java:21) at members.AppointmentDialog$1.actionPerformed(AppointmentDialog.java:101) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236) [...]]]></description>
			<content:encoded><![CDATA[<p>Full error message:</p>
<pre class="code brush:plain">Exception occurred during event dispatching:
org.hibernate.HibernateException: identifier of an instance of members.Appointment was altered from 8 to 8
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:58)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:157)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:113)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at members.AppointmentDialog.jButtonSaveActionPerformed(AppointmentDialog.java:279)
at members.AppointmentDialog.access$000(AppointmentDialog.java:21)
at members.AppointmentDialog$1.actionPerformed(AppointmentDialog.java:101)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:5517)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3135)
at java.awt.Component.processEvent(Component.java:5282)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3984)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1791)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:153)
at java.awt.Dialog$1.run(Dialog.java:535)
at java.awt.Dialog$2.run(Dialog.java:563)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Dialog.java:561)
at java.awt.Component.show(Component.java:1302)
at java.awt.Component.setVisible(Component.java:1255)
at admin.AdminOptionsForm.jButtonSetAppointmentActionPerformed(AdminOptionsForm.java:238)
at admin.AdminOptionsForm.access$800(AdminOptionsForm.java:24)
at admin.AdminOptionsForm$9.actionPerformed(AdminOptionsForm.java:145)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:5517)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3135)
at java.awt.Component.processEvent(Component.java:5282)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3984)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1791)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)</pre>
<p>In Java, I had a class Appointment mapped to a MySQL table `appointment` using Hibernate as follows:</p>
<pre class="code brush:xml">&lt;hibernate-mapping&gt;
&lt;class name="members.Appointment" table="appointment"&gt;
&lt;id name="idAppointment" column="idappointment" type="short"&gt;
&lt;generator class="native"/&gt;
&lt;/id&gt;
&lt;many-to-one name="member" column="idmember" not-null="true" foreign-key="fk_idmember"/&gt;
&lt;property name="startDate" type="timestamp" column="start_date"/&gt;
&lt;property name="duration" type="short" column="duration" length="3"/&gt;
&lt;property name="cancelled" type="boolean"/&gt;
&lt;/class&gt;
&lt;/hibernate-mapping&gt;</pre>
<p>I was getting the error when inserting a new appointment into the database.</p>
<p>The problem was that the idAppointment member variable in the Java class and the idappointment field in the MySQL database table were of the type int. So why the hell did I have the type short in the mapping? The answer is simple: because of the copy paste. So the correct code is:</p>
<pre class="code brush:xml">&lt;id name="idAppointment" column="idappointment"&gt;
&lt;generator class="native"/&gt;
&lt;/id&gt;
</pre>
<p><strong>Conclusion</strong>: copy paste is sometimes evil.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theerrormessage.com/2007/08/orghibernatehibernateexception-identifier-of-an-instance-of-membersappointment-was-altered-from-8-to-8/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>java.sql.SQLException: Cannot convert value &#8217;0000-00-00 00:00:00&#8242; from column 9 to TIMESTAMP</title>
		<link>http://www.theerrormessage.com/2007/07/javasqlsqlexception-cannot-convert-value-0000-00-00-000000-from-column-9-to-timestamp/</link>
		<comments>http://www.theerrormessage.com/2007/07/javasqlsqlexception-cannot-convert-value-0000-00-00-000000-from-column-9-to-timestamp/#comments</comments>
		<pubDate>Fri, 27 Jul 2007 00:14:25 +0000</pubDate>
		<dc:creator>thalissar</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.theerrormessage.com/2007/07/26/javasqlsqlexception-cannot-convert-value-0000-00-00-000000-from-column-9-to-timestamp/</guid>
		<description><![CDATA[Full error message: Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:2223) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104) at org.hibernate.loader.Loader.list(Loader.java:2099) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79) at admin.MembersTableModel.&#60;init&#62;(MembersTableModel.java:43) at admin.AdminOptionsForm.initComponents(AdminOptionsForm.java:98) at admin.AdminOptionsForm.&#60;init&#62;(AdminOptionsForm.java:32) at managemembers.Main.main(Main.java:45) Caused by: java.sql.SQLException: Cannot convert value '0000-00-00 00:00:00' from column 9 to TIMESTAMP. [...]]]></description>
			<content:encoded><![CDATA[<p>Full error message:</p>
<pre class="code brush:plain">Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2223)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at admin.MembersTableModel.&lt;init&gt;(MembersTableModel.java:43)
at admin.AdminOptionsForm.initComponents(AdminOptionsForm.java:98)
at admin.AdminOptionsForm.&lt;init&gt;(AdminOptionsForm.java:32)
at managemembers.Main.main(Main.java:45)
Caused by: java.sql.SQLException: Cannot convert value '0000-00-00 00:00:00' from column 9 to TIMESTAMP.
at com.mysql.jdbc.ResultSet.getTimestampFromBytes(ResultSet.java:6864)
at com.mysql.jdbc.ResultSet.getTimestampInternal(ResultSet.java:6899)
at com.mysql.jdbc.ResultSet.getTimestamp(ResultSet.java:6218)
at com.mysql.jdbc.ResultSet.getTimestamp(ResultSet.java:6256)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.getTimestamp(NewProxyResultSet.java:3394)
at org.hibernate.type.TimestampType.get(TimestampType.java:30)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2096)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1380)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1308)
at org.hibernate.loader.Loader.getRow(Loader.java:1206)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
at org.hibernate.loader.Loader.doQuery(Loader.java:701)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
... 11 more</pre>
<p>My example:</p>
<p>// the Java class</p>
<pre class="code brush:java">public class Member  {
// some private member attributes
private Date addedDate;
// proper getter and setter methods
}</pre>
<p>&lt;!&#8211; the Hibernate mapping&#8211;&gt;</p>
<pre class="code brush:xml">&lt;hibernate-mapping&gt;
&lt;class name="managemembers.Member" table="member"&gt;
&lt;!-- some mappings here--&gt;
&lt;property name="addedDate" type="timestamp" column="added_date"/&gt;
&lt;/class&gt;
&lt;/hibernate-mapping&gt;</pre>
<p># The MySQL table</p>
<pre class="code brush:sql">CREATE TABLE `member` (
# some fields here
`added_date` DATETIME,
) ;</pre>
<p>So I was mapping a java.util.Date field in the POJO to a MySQL DATETIME field.</p>
<p>The error occured while I was trying to retrieve the data from the member database table.</p>
<p>The problem was that I had DATETIME values in the database with all-zero components (0000-00-00 &#8230;), so the solution was to set all the added_date field values with all-zero components to NULL and to be careful to set a valid DATETIME value or NULL into the added_date field each time I inserted a new row.</p>
<p><strong>Conclusion</strong>: You have 2 choices: either set the date field in the table to a NULL value either set it to a valid date.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theerrormessage.com/2007/07/javasqlsqlexception-cannot-convert-value-0000-00-00-000000-from-column-9-to-timestamp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

