-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: java.sql.Timestamp intances returned instead of java.util.Da
PostPosted: Tue Jun 22, 2004 9:19 am 
Newbie

Joined: Mon Feb 09, 2004 6:45 pm
Posts: 10
Location: Feltre, BL Italy
Hi all.
Using the following mapping definition for class Item, it is
correclty incarnated when I perform queries using
the Criteria interface: the Item.anagModifyDate gets type java.util.Date.
Unfortunately, my app often needs to perform queries like:
SELECT item.anagModifyDate FROM Item AS item
via the Query interface, Query.list() method
This returns a list of java.sql.Timestamp, that I could not
compare (using e.g. java.util.Collections.binarySearch) whith
a template Item instance (the member anagModifyDate gets
the java.util.Date that should be searched in the list returned
by the Query).
Is there any way to force Hibernate to return java.util.Date
for tmestamp values?
I'm I misusing Hibernate somehow?
thanks
davide

Hibernate 2.1.4 (2.6.2004)

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="it.pollisrl.gpv.item.Item"
table="HIB_ITEM"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="ID"
type="java.lang.String"
>
<generator class="uuid.hex">
</generator>
</id>

<discriminator
column="class"
type="string"
/>

<property
name="supplierCode"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="SUPPLIER_CODE"
sql-type="VARCHAR(255)"
/>
</property>

<property
name="reorderCode"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="REORDER_CODE"
sql-type="VARCHAR(255)"
/>
</property>

<property
name="innerCode"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="INNER_CODE"
sql-type="VARCHAR(255)"
/>
</property>

<property
name="descr"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="DESCR"
sql-type="VARCHAR(255)"
/>
</property>

<property
name="display"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="DISPLAY"
sql-type="VARCHAR(255)"
/>
</property>

<property
name="shortDescr"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="SHORT_DESCR"
sql-type="VARCHAR(255)"
/>
</property>

<property
name="vat"
type="int"
update="true"
insert="true"
>
<column
name="VAT"
sql-type="INTEGER(9)"
/>
</property>

<property
name="weight"
type="java.math.BigDecimal"
update="true"
insert="true"
>
<column
name="WEIGHT"
sql-type="DECIMAL(10,3)"
/>
</property>

<property
name="mu"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="MU"
sql-type="VARCHAR(255)"
/>
</property>

<property
name="packing"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="PACKING"
sql-type="VARCHAR(255)"
/>
</property>

<property
name="numPackages"
type="int"
update="true"
insert="true"
>
<column
name="NUM_PACKAGES"
sql-type="INTEGER(9)"
/>
</property>

<property
name="stored"
type="boolean"
update="true"
insert="true"
>
<column
name="STORED"
sql-type="BIT"
/>
</property>

<property
name="sendToECR"
type="boolean"
update="true"
insert="true"
>
<column
name="SEND_TO_E_C_R"
sql-type="BIT"
/>
</property>

<property
name="recharge"
type="boolean"
update="true"
insert="true"
>
<column
name="RECHARGE"
sql-type="BIT"
/>
</property>

<property
name="anagModifyDate"
type="java.util.Date"
update="true"
insert="true"
>
<column
name="ANAG_MODIFY_DATE"
sql-type="DATETIME"
/>
</property>

<property
name="buyCostModifyDate"
type="java.util.Date"
update="true"
insert="true"
>
<column
name="BUY_COST_MODIFY_DATE"
sql-type="DATETIME"
/>
</property>

<property
name="sellPriceModifyDate"
type="java.util.Date"
update="true"
insert="true"
>
<column
name="SELL_PRICE_MODIFY_DATE"
sql-type="DATETIME"
/>
</property>

<property
name="lastBuyDate"
type="java.util.Date"
update="true"
insert="true"
>
<column
name="LAST_BUY_DATE"
sql-type="DATETIME"
/>
</property>

<property
name="groupCode"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="GROUP_CODE"
sql-type="VARCHAR(255)"
/>
</property>

<property
name="shelf"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="SHELF"
sql-type="VARCHAR(255)"
/>
</property>

<property
name="subtotalDiscountable"
type="boolean"
update="true"
insert="true"
>
<column
name="SUBTOTAL_DISCOUNTABLE"
sql-type="BIT"
/>
</property>

<many-to-one
name="category"
class="it.pollisrl.gpv.category.Category"
cascade="none"
outer-join="false"
update="true"
insert="true"
column="CATEGORY_FK"
/>

<set
name="barcodes"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>

<key
column="ITEM_FK"
/>

<one-to-many
class="it.pollisrl.gpv.barcode.Barcode"
/>
</set>

<set
name="priceListItems"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>

<key
column="ITEM_FK"
/>

<one-to-many
class="it.pollisrl.gpv.pricelist.PriceListItem"
/>
</set>

<set
name="offerRows"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>

<key
column="ITEM_FK"
/>

<one-to-many
class="it.pollisrl.gpv.offer.OfferRow"
/>
</set>

<many-to-one
name="reparto"
class="it.pollisrl.gpv.reparto.Reparto"
cascade="none"
outer-join="false"
update="true"
insert="true"
column="REPARTO_FK"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Item.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="it.pollisrl.gpv.item.ItemImpl"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="ItemImpl"
>

</subclass>

</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 10:23 am 
Newbie

Joined: Mon Feb 02, 2004 10:12 am
Posts: 5
Hi,

I've got the same kind of problem, but in my case the query return a sub class of java.sql.Timestamp (Sybase driver). I also use Hibernate 2.1.4.

So, when I compare this date with a java.util.Date with date1.equals(date2) the test return false, even if the milliseconds are the same (the equals method test if the dates are of the same Class).

To avoid this, I've changed my setters like this :

Code:
   public void setDate(Date date) {
      if (date instanceof Timestamp) {
         this.date = new Date(date.getTime());
      } else {
         this.date = date;
      }
   }


I dont like it, but I see no other way.
So, if anyone knows how to force Hibernate to use java.util.Date instead of any of its subclass, please let me know.

Thanks
Jerome


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 10:28 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://forum.hibernate.org/viewtopic.php?t=925275

http://forum.hibernate.org/viewtopic.php?t=927602

The problem is the equals() method in Java Timestamp.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.