<?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>UKoom &#187; Hibernate</title>
	<atom:link href="http://www.ukoom.com/tag/hibernate/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ukoom.com</link>
	<description>Documentum, SharePoint, Alfresco, ECM...</description>
	<lastBuildDate>Tue, 25 Oct 2011 15:11:22 +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>The requested operation is not supported on forward only result sets</title>
		<link>http://www.ukoom.com/the-requested-operation-is-not-supported-on-forward-only-result-sets.htm</link>
		<comments>http://www.ukoom.com/the-requested-operation-is-not-supported-on-forward-only-result-sets.htm#comments</comments>
		<pubDate>Sat, 31 Jul 2010 08:51:29 +0000</pubDate>
		<dc:creator>ukoom</dc:creator>
				<category><![CDATA[Documentum]]></category>
		<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false">http://www.ukoom.com/?p=1078</guid>
		<description><![CDATA[public Object doInHibernate(Session session) throws HibernateException { Query q = session.createQuery(dql); q.setFirstResult(size); q.setMaxResults(rInfo.getPageSize()); return q.list(); } We need to make sure the value of  parameter of query.setFirstResult is bigger than 0. And it seems that we can also check if hibernate.jdbc.use_scrollable_resultset is set to true. I didn&#8217;t try this for I resolve this issue by [...]]]></description>
			<content:encoded><![CDATA[<h3>public Object doInHibernate(Session session) throws HibernateException {<br />
Query q = session.createQuery(dql);<br />
q.setFirstResult(size);<br />
q.setMaxResults(rInfo.getPageSize());<br />
return q.list();<br />
}</h3>
<p>We need to make sure the value of  parameter of query.setFirstResult is bigger than 0.</p>
<p>And it seems that we can also check if hibernate.jdbc.use_scrollable_resultset is set to true. I didn&#8217;t try this for I resolve this issue by setting the correct first result size.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ukoom.com/the-requested-operation-is-not-supported-on-forward-only-result-sets.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hibernate Study Note</title>
		<link>http://www.ukoom.com/hibernate-study-note.htm</link>
		<comments>http://www.ukoom.com/hibernate-study-note.htm#comments</comments>
		<pubDate>Mon, 05 Jan 2009 05:16:11 +0000</pubDate>
		<dc:creator>ukoom</dc:creator>
				<category><![CDATA[Team Fight]]></category>
		<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false">http://www.ukoom.com/?p=420</guid>
		<description><![CDATA[This is my study note about hibernate, which is written around two years ago. Hibernate =========================================================== Books: Java Persistence with Hibernate Database Manipulation &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; Process of retrieveing objects * Search in the Session Cache. * Search in the &#8220;NonExists&#8221; record * Search in the sessionFactory Cache if it could. * Select SQL, (add the infomation [...]]]></description>
			<content:encoded><![CDATA[<p>This is my study note about hibernate, which is written around two years ago.</p>
<p>Hibernate<br />
===========================================================</p>
<p>Books:<br />
Java Persistence with Hibernate</p>
<p>Database Manipulation<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Process of retrieveing objects<br />
* Search in the Session Cache.<br />
* Search in the &#8220;NonExists&#8221; record<br />
* Search in the sessionFactory Cache if it could.<br />
* Select SQL, (add the infomation in the &#8220;NonExists&#8221; record if object not exsist, and return null.)<br />
* Use the ResultSet to get the obejct.<br />
* Bring the object to Session Cache.<br />
* Excute the Inteceptor.onLoad().<br />
* Bring the object to Session Factory Cache.<br />
* Excute the onLoad() if obejct has implemented the LifeCycle interface.<br />
* Return the object.</p>
<p>get() and load()<br />
* if the object not exsist, Null will be returned by get(), and ObjectNotFoundException by load().<br />
* load() could return a proxy class and use the sessionFactory cache.</p>
<p>find() and iterate()<br />
* Hibernate 2 &#8216;s Query and Criteria are based on these two methods, Session.find() equals Session.createQuery.list(), Session.iterate() equals Session.createQuery.iterate() in version 3.</p>
<p>save(), update() and saveOrUpdate()</p>
<p>list()<br />
uniqueResult()</p>
<p>Priciple<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Instance states<br />
* transient  (has no persistent identity)<br />
* persistent (has a persistent identity and, perhaps, a corresponding row in the database,guarantees that persistent identity is equivalent to Java identity)<br />
* detached   (has a persistent identity and, perhaps, a corresponding row in the database, no guarantees about the relationship between persistent identity and Java identity)<br />
* switch</p>
<p>|&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; END (garbage collection)&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
|       save(), saveOrUpdate()                   close(), evict(), clear()           |<br />
@&#8212;new()&#8211;&gt; transient &lt;===========================&gt; persistent &lt;==============================&gt; detached&#8212;<br />
|                delete()        |        update(), saveOrUpdate()<br />
|    get(), load(), find(), iterator(), list()&#8230;    |<br />
|&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
* Judge states of transientg and detached<br />
- id unsaved-value<br />
- version<br />
- if Interceptor.isUnsaved return True<br />
* PO(persistence object) vs VO (value object)<br />
Judge: if managed by Entity Map<br />
Extends: VO as a DTO(Data Transfer Object)<br />
Usage: Apache Jakarta Commons Beanutils to copy properties. (throws IllegalAccessExcpetion)</p>
<p>Object identify and equality<br />
* compare with memory address (&#8220;==&#8221;)<br />
* compare with infomation      (equals() and hashCode())<br />
we have to override the equals() nad hashCode() methods if we intend to put instansts of persistence classes in a Set and<br />
intend to use reattchement of detatched instances.</p>
<p>Dirty Data Checking(Two ways)<br />
&#8211; 1. Checking the data object (Check the setter methods by Dynamic Proxy Pattern or CGLIB)<br />
&#8211; 2. Compare with data version (Adopted by Hibernate)<br />
public void commit() throws HibernateException(){<br />
&#8230;&#8230;<br />
if( session.getFlushMode()!= FlushMode.NEVER) session.flush(); //flushEverything();<br />
&#8230;&#8230;<br />
}<br />
Attribution of EntityEntry &#8212; loadedState.</p>
<p>Data Cache Strategy<br />
* Transaction level Cache<br />
* Application/Process level Cache<br />
* Cluster level cache<br />
* Cache in Hibernate:<br />
- use the identifier to load data. (Session.load(), Session.iterate())<br />
- Lazy-init<br />
- Session Level    (Session.evict, Session.clear)<br />
- SessionFactory Level (support a simple Hashtable [org.hibernate.cache.HashtableCacheProvider],<br />
third party cache: JCS, EHCache, OSCache, JBoss Cache, SwarmCache)</p>
<p>Transactions and Concurrency<br />
* ACID (Atomic, Consistency, Isolation, Durability)<br />
* Based on JDBC<br />
session = sessionFactory.openSession();<br />
Transaction tx = session.beginTransaction();<br />
&#8230;&#8230;<br />
tx.commit();</p>
<p>Connection conn = getConnection();<br />
conn.setAutoCommit(false);  // AutoCommit has been set to false when openSession(), so if no transaction, the save() method will not<br />
// affect the db(support tranaction)<br />
&#8230;&#8230;<br />
conn.commit();</p>
<p>* Based on JTA (Java Transaction API,UserTransaction, TransactionManager, Transaction)<br />
JTA can span many connections or sessions.<br />
Session.beginTransaction have call the IntitialContext.lookup()<br />
Easy to use JTA in EJB, because there is no need to call transaction manager in the code.</p>
<p>Concurrency<br />
Locking<br />
* Pessimistic Locking (use the &#8220;for update&#8221; statement)<br />
String hqlStr = &#8220;from Student as stu where stu.name = &#8216;lidnux&#8217;&#8221;<br />
Query query = session.createQuery(hqlStr);<br />
query.setLockMode(&#8220;stu&#8221;, LockMode.UPGRADE);<br />
query.list();<br />
* LockMode<br />
//<br />
LockMode.NONE<br />
LockMode.WRITE<br />
LockMode.READ</p>
<p>LockMode.UPGRATE<br />
LockMode.UPGRATE_NOWAIT</p>
<p>* Set the LockMode<br />
Criteria.setLockMode<br />
Query.setLockMode<br />
Session.lock</p>
<p>* Optimistic Locking</p>
<p>Relationship<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
id<br />
* Generator<br />
increment/identify/sequence/hilo/seqhilo/uuid/guid/native/assigned/select/foreign/sequence-identify<br />
One-to-One association (two varieties)<br />
&#8211; 1. primary key association (A special Hibernate identifier generation strategy called foreign)<br />
* Add mappings<br />
&lt;one-to-one name=&#8221;certificate&#8221; class=&#8221;lidnux.model.certificate&#8221; fetch=&#8221;join&#8221; cascade=&#8221;all&#8221;/&gt;<br />
&lt;one-to-one name=&#8221;student&#8221; class=&#8221;lidnux.model.student&#8221; constrainted=&#8221;true&#8221;/&gt;<br />
one-to-one association has no column element, we can specify it in id element.<br />
* Use identifier generation<br />
&lt;id&gt;<br />
&lt;generator&gt;<br />
&lt;param name=&#8221;peroperty&#8221;&gt;student&lt;/param&gt;<br />
&lt;/generator&gt;<br />
&lt;/id&gt;<br />
* Use in code<br />
student.setCertificate(certificate);<br />
cerfificate.setStudent(student); //requeried<br />
StudentDAO.save(student);     //cascade save</p>
<p>&#8211; 2. unique foreign key association (many-to-one association with unique element to make bidirectional association)<br />
* Add mappings<br />
&lt;one-to-one name=&#8221;certificate&#8221; class=&#8221;lidnux.model.certificate&#8221; fetch=&#8221;join&#8221; cascade=&#8221;all&#8221; /&gt;<br />
&lt;many-to-one name=&#8221;student&#8221; class=&#8221;lidnux.model.student&#8221; unique=&#8221;true&#8221; column=&#8221;student_id&#8221; /&gt;</p>
<p>Many-to-Many association</p>
<p>Query<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Criteria Query<br />
* Narrowing the result set<br />
List students = session.createCriteria()<br />
.add( Restrictions.like(&#8220;name&#8221;, &#8220;lidnux%&#8221;))<br />
.add( Restrictions.between(&#8220;weight&#8221;, minWeight, maxWeight))<br />
.list();<br />
Built-in criterion types;<br />
To specify SQL directly:<br />
// {alias} placeholder with be replaced by the row alias of the queried entity.<br />
.add( Restrictions.sqlRestriction(&#8220;lower({alias}.name) like lower(?)&#8221;, &#8220;Lidnux%&#8221;, Hibernate.STRING) )<br />
To get a criterion from a Property instance<br />
Property age = Property.forName(&#8220;age&#8221;);<br />
List students = session.createCriteria(Student.class)<br />
.add( Restrictions.disjunction()<br />
.add( age.isNull() )<br />
.add( age.eq( new Integer(0) ) )<br />
.add( age.eq( new Integer(1) ) )<br />
.add( age.eq( new Integer(2) ) )<br />
) )<br />
.add( Property.forName(&#8220;name&#8221;).in( new String[] { &#8220;Lidnux&#8221;, &#8220;Lidanux&#8221;, &#8220;Dan&#8221; } ) )<br />
.list();<br />
* Ordering the results<br />
.addOrder( Order.asc(&#8220;name&#8221;) )<br />
.addOrder( Order.desc(&#8220;age&#8221;) )<br />
.setMaxResults(50)<br />
.list();</p>
<p>.add( Property.forName(&#8220;name&#8221;).like(&#8220;F%&#8221;) )<br />
.addOrder( Property.forName(&#8220;name&#8221;).asc() )<br />
.addOrder( Property.forName(&#8220;age&#8221;).desc() )<br />
.setMaxResults(50)<br />
.list();</p>
<p>* Associations<br />
List teams = sess.createCriteria(Team.class)<br />
.add( Restrictions.like(&#8220;name&#8221;, &#8220;03242%&#8221;) )<br />
.createCriteria(&#8220;students&#8221;)                      //return a new instance of Criteria,which refers to the elements of the student collection.<br />
.add( Restrictions.like(&#8220;name&#8221;, &#8220;lidnux%&#8221;))<br />
.list();</p>
<p>In certain circumstances, this method is useful<br />
List teams = session.createCriteria(Team.class)<br />
.createAlias(&#8220;students&#8221;, stu)<br />
.add(Restrictions.like(stu.name,&#8221;lidnux%&#8221;)<br />
.list();</p>
<p>Session.get/load的区别：<br />
1.如果未能发现符合条件的记录，get方法返回null，而load方法会抛出一个ObejctNotFoundException。<br />
2.Load方法可返回实体的代理类类型，而get方法永远直接返回实体类。<br />
3.Load方法可以充分利用内部缓存和二级缓存中现有数据，而get方法则仅仅在内部缓存中进行数据查找，如没有发现对应数据，将越过二级缓存，直接调用SQL完成数据读取。<br />
<a href="http://www.ukoom.com/wp-content/uploads/2009/01/hibernate-study-note.txt">hibernate-study-note.txt</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ukoom.com/hibernate-study-note.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Classic hibernate operation method</title>
		<link>http://www.ukoom.com/classic-hibernate-operation-method.htm</link>
		<comments>http://www.ukoom.com/classic-hibernate-operation-method.htm#comments</comments>
		<pubDate>Wed, 17 Dec 2008 00:13:30 +0000</pubDate>
		<dc:creator>ukoom</dc:creator>
				<category><![CDATA[Team Fight]]></category>
		<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false">http://www.ukoom.com/?p=308</guid>
		<description><![CDATA[HQL http://www.hibernate.org/hib_docs/nhibernate/html/queryhql.html BaseDAO http://www.koders.com/java/fid79A3087E1148CE1F7E44FB92DA3E1D6BD8B62DC8.aspx?s=hibernate#L1 CoolSample http://svn.apache.org/repos/asf/roller/branches/roller_3.0/src/org/apache/roller/business/hibernate/HibernateRefererManagerImpl.java http://www.koders.com/java/fidA60C168CC1294821210D40681702FC0489E526BC.aspx?s=hibernate#L16 http://www.koders.com/java/fidAE88092715E8DA77024EA1DBFAD9FE19CAC2DA21.aspx FYI]]></description>
			<content:encoded><![CDATA[<p>HQL</p>
<p>http://www.hibernate.org/hib_docs/nhibernate/html/queryhql.html</p>
<p>BaseDAO</p>
<p>http://www.koders.com/java/fid79A3087E1148CE1F7E44FB92DA3E1D6BD8B62DC8.aspx?s=hibernate#L1</p>
<p>CoolSample</p>
<p>http://svn.apache.org/repos/asf/roller/branches/roller_3.0/src/org/apache/roller/business/hibernate/HibernateRefererManagerImpl.java</p>
<p>http://www.koders.com/java/fidA60C168CC1294821210D40681702FC0489E526BC.aspx?s=hibernate#L16</p>
<p>http://www.koders.com/java/fidAE88092715E8DA77024EA1DBFAD9FE19CAC2DA21.aspx</p>
<p>FYI</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ukoom.com/classic-hibernate-operation-method.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mapping Oracle Long and Clob Type in Hibernate</title>
		<link>http://www.ukoom.com/mapping-oracle-long-and-clob-type-in-hibernate.htm</link>
		<comments>http://www.ukoom.com/mapping-oracle-long-and-clob-type-in-hibernate.htm#comments</comments>
		<pubDate>Wed, 17 Dec 2008 00:07:11 +0000</pubDate>
		<dc:creator>ukoom</dc:creator>
				<category><![CDATA[Team Fight]]></category>
		<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false">http://www.ukoom.com/?p=305</guid>
		<description><![CDATA[Hi All, It is interesting. My opinion and investigation: Oralce strongly recommend not to use LONG datatype in oracle, especially above oracle 8.LONG type is just for backward compatibility. And the use of LONG datatype is subject to many restrictions. like Hanjin said, the LONG column cannot appear in WHERE clasuses. A table can contain [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><span style="font-size: x-small; font-family: Arial; color: navy;"><span style="font-size: 10pt; font-family: Arial; color: navy;">Hi  All,</span></span></p>
<p class="MsoNormal"><span style="font-size: x-small; font-family: Arial; color: navy;"><span style="font-size: 10pt; font-family: Arial; color: navy;">It is interesting. </span></span><span style="font-size: x-small; font-family: Arial; color: navy;"><span style="font-size: 10pt; font-family: Arial; color: navy;"> </span></span></p>
<p class="MsoNormal"><span style="font-size: x-small; font-family: Arial; color: navy;"><span style="font-size: 10pt; font-family: Arial; color: navy;">My opinion and  investigation:</span></span></p>
<ol style="margin-top: 0cm;" type="1">
<li class="MsoNormal" style="color: navy;"><span style="font-size: x-small; font-family: Arial; color: navy;"><span style="font-size: 10pt; font-family: Arial;">Oralce strongly recommend not to use  LONG datatype in oracle, especially above oracle 8.LONG type is just for  backward compatibility.</span></span></li>
</ol>
<p class="MsoNormal" style="margin-left: 36pt;"><span style="font-size: x-small; font-family: Arial; color: navy;"><span style="font-size: 10pt; font-family: Arial; color: navy;">And the use of LONG  datatype is subject to many restrictions. </span></span></p>
<ol style="margin-top: 0cm;" type="1">
<li>
<ol style="margin-top: 0cm;" type="a">
<li class="MsoNormal" style="color: navy;"><span style="font-size: x-small; font-family: Arial; color: navy;"><span style="font-size: 10pt; font-family: Arial;">like Hanjin said, the LONG column  cannot appear in WHERE clasuses.</span></span></li>
<li class="MsoNormal" style="color: navy;"><span style="font-size: x-small; font-family: Arial; color: navy;"><span style="font-size: 10pt; font-family: Arial;">A table can contain only one LONG  column , although this is not a problem for us now.</span></span></li>
<li class="MsoNormal" style="color: navy;"><span style="font-size: x-small; font-family: Arial; color: navy;"><span style="font-size: 10pt; font-family: Arial;">…</span></span></li>
</ol>
</li>
<li class="MsoNormal" style="color: navy;"><span style="font-size: x-small; font-family: Arial; color: navy;"><span style="font-size: 10pt; font-family: Arial;">Hibernate doesn’t come with the  support of manipulation for CLOB column. </span><span style="font-size: 10pt; font-family: Arial;"> It is difficult to deal with those  CLOB column.( http://www.hibernate.org/76.html<a title="blocked::http://www.hibernate.org/76.html" href="http://www.hibernate.org/76.html"></a> and http://www.hibernate.org/56.html)<br />
Typically,  we can creat a new type to get/set CLOB value. </span></span></li>
</ol>
<p class="MsoNormal" style="margin-left: 36pt;"><span style="font-size: x-small; font-family: Arial; color: navy;"><span style="font-size: 10pt; font-family: Arial; color: navy;">But dear spring has  already invented a wheel &#8211;  org.springframework.orm.hibernate3.support.ClobStringType.</span></span></p>
<p class="MsoNormal" style="margin-left: 36pt;"><span style="font-size: x-small; font-family: Arial; color: navy;"><span style="font-size: 10pt; font-family: Arial; color: navy;">If interested with it,  you can look into its source code. </span></span><span style="font-size: x-small; font-family: Arial; color: navy;"><span style="font-size: 10pt; font-family: Arial; color: navy;"> </span></span></p>
<p class="MsoNormal" style="margin-left: 36pt;"><span style="font-size: x-small; font-family: Arial; color: navy;"><span style="font-size: 10pt; font-family: Arial; color: navy;">I checked in the  updated codes (***.hbm.xml and applicationContext-hibernate.xml), FYI. </span></span></p>
<p class="MsoNormal"><span style="font-size: x-small; font-family: Arial; color: navy;"><span style="font-size: 10pt; font-family: Arial; color: navy;">Best  regards,</span></span></p>
<p class="MsoNormal"><span style="font-size: x-small; font-family: Arial; color: navy;"><span style="font-size: 10pt; font-family: Arial; color: navy;">Dan</span></span></p>
<p class="MsoNormal">Attached zip file contains some related articles.</p>
<p class="MsoNormal"><a href="http://www.ukoom.com/wp-content/uploads/2008/12/oracle-clob-long-in-hibernate.zip">oracle-clob-long-in-hibernate.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ukoom.com/mapping-oracle-long-and-clob-type-in-hibernate.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hibernate lost timezone when getting timestamp from Oracle</title>
		<link>http://www.ukoom.com/hibernate-lost-timezone-when-getting-timestamp-from-oracle.htm</link>
		<comments>http://www.ukoom.com/hibernate-lost-timezone-when-getting-timestamp-from-oracle.htm#comments</comments>
		<pubDate>Wed, 12 Nov 2008 08:11:42 +0000</pubDate>
		<dc:creator>ukoom</dc:creator>
				<category><![CDATA[Team Fight]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.ukoom.com/?p=69</guid>
		<description><![CDATA[These two days, I was working on getting timezone information from oracle using Hibernate. The version of Hibernate is 3.2.4. I found that the return value always returned a Calendar with the tomcat server&#8217;s timezone when we were getting a Calendar field. My environment: a column with data type as &#8220;TIMESTAMP WITH TIME ZONE DEFAULT [...]]]></description>
			<content:encoded><![CDATA[<p>These two days, I was working on getting timezone information from oracle using Hibernate. The version of Hibernate is 3.2.4.  I found that the return value always returned a Calendar with the tomcat server&#8217;s timezone when we were getting a Calendar field.</p>
<p>My environment:  a column with data type as &#8220;TIMESTAMP WITH TIME ZONE DEFAULT SYSTIMESTAMP&#8221; (Oracle 10g).  You can find my another article about TIMESTAMP/Date in oracle. <img src='http://www.ukoom.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Firstly, Google ~  It told me that there was a bug about this in Hibernate 2.*.</p>
<p>&#8220;Calendar loses time zone information<br />
Affects Version/s:     2.1.3<br />
Fix Version/s:     3.0 alpha<br />
http://opensource.atlassian.com/projects/hibernate/browse/HB-1006&#8243;</p>
<p>But this bug is just for saving a Calender with timezone.  It has been fixed in Hibernate 3.*.</p>
<p>So I traced the hibernate source code:</p>
<pre class="java:collapse">	public Object get(ResultSet rs, String name) throws HibernateException, SQLException {

		Timestamp ts = rs.getTimestamp(name);
		if (ts!=null) {
			Calendar cal = new GregorianCalendar();
			if ( Environment.jvmHasTimestampBug() ) {
				cal.setTime( new Date( ts.getTime() + ts.getNanos() / 1000000 ) );
			}
			else {
				cal.setTime(ts);
			}
			return cal;
		}
		else {
			return null;
		}

	}

	public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
		final Calendar cal = (Calendar) value;
		//st.setTimestamp( index,  new Timestamp( cal.getTimeInMillis() ), cal ); //JDK 1.5 only
		st.setTimestamp( index,  new Timestamp( cal.getTime().getTime() ), cal );
	}</pre>
<p>I think CalendarType.get() doesn&#8217;t assemble the Calendar with the timezone. So we store the date with GMT timezone and convert it to other timezone when getting it out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ukoom.com/hibernate-lost-timezone-when-getting-timestamp-from-oracle.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

