-->
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.  [ 15 posts ] 
Author Message
 Post subject: Oracle sequence + Date format
PostPosted: Thu Aug 12, 2004 6:09 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
Hibernate version: 2.1.5

Hi all,

I have a problem concerning Date and I understand nothing about it, it's crazy.
I have a table very simple with Id, Name and Date... only for test.
I create a POJO object like this :

Person p = new Person();
p.setName("Doo");
p.setDate(new Date());

If I use that code, my key is strane in database 4,54154541E12.
This is my log trace...
11:58:48,671 DEBUG [DriverManagerConnectionProvider] - using pooled JDBC connect
ion, pool size: 0
11:58:48,671 DEBUG [SQL] - select WTOLD.SEQ.nextval from dual
11:58:48,701 DEBUG [SQL] - insert into WTOLD.PANEL (SHORTNAME, FULLNAME, DATEEST
ABLISHED, ID) values (?, ?, ?, ?)
11:58:48,711 DEBUG [UpdateTimestampsCache] - Invalidating space [WTOLD.PANEL]
11:58:48,711 DEBUG [DriverManagerConnectionProvider] - returning connection to p
ool, pool size: 1
11:58:48,731 INFO [InitServlet] - Resultat hibernate : 1920 org.eu.legalservice
.wtold.bo.Panel@177b4d3[id=1920]

As you can see Hibernate keep the good sequence value and if I try a get on my POJO I have the good value but not in database.

If I try a session.save(p) without set the Date value and only the name, the value of the sequence in database is ok 1920 for example.
I understand nothing, I try different Oracle driver but it's always the same thing.
I have a TimeStamp in mapping files and java.util.Date in POJO.

I try to play with different Date type in my mapping files and if I use java.sql.date instead of java.util.Date it's ok but I haven't got the time only D,M and Y.

Is it someone who know why I have this probem, why in function of my Date format my sequence id takes a strange value? creazy no?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 12, 2004 6:54 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
I try this code :

java.sql.Date date = null;
pBo.setDateestablished(date.valueOf("2004-08-04"));

with all my Date format in POJO or mapping with java.sql.Date and my id in database is correct but I don't understand why Date format mofify the format of the key of my POJO because Date is only a field in my table and not my key or another thing.

Maybe it comes from JDBC or hibernate Dialect?
If you have any idea could you give me a way of reflexion:+)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 12, 2004 7:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
I must be missing something because I have no idea what you are talking about.

So you have a java.util.Date property mapped using the "timestamp" type. What happens when you try to save it? It inserts the row but drops the time portion from the Date property?

That does not make sense.

The way I've mapped this using Oracle8i is specifying type="java.util.Date" in the Hibernate mapping. Worked fine. But that should be the same as mapping type="timestamp".


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 12, 2004 8:08 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
So i ll try to explain better my problem...

<?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>
<!--
Created by the Middlegen Hibernate plugin 2.1

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="org.eu.legalservice.wtold.bo.Panel"
table="PANEL"
schema="WTOLD"
>

<id
name="id"
type="java.lang.Integer"
column="ID"
>
<generator class="sequence">
<param name="sequence">WTOLD.SEQ</param>
</generator>
</id>

<property
name="shortname"
type="java.lang.String"
column="SHORTNAME"
not-null="true"
length="20"
/>
<property
name="fullname"
type="java.lang.String"
column="FULLNAME"
not-null="true"
length="60"
/>
<property
name="dateestablished"
type="java.sql.Date"
column="DATEESTABLISHED"
length="7"
/>

<!-- Associations -->

<!-- uni-directional one-to-many association to Panelmembership -->
<set
name="panelmemberships"
lazy="true"
cascade="none"
>
<key>
<column name="PANEL_ID" />
</key>
<one-to-many
class="org.eu.legalservice.wtold.bo.Panelmembership"
/>
</set>

</class>
</hibernate-mapping>

this is one of my mapping file...

If I use a java.sql.Date all works fine.
But if I use a util.Date or a TimeStamp, I have a probem in database...
I don't know why but the value of my sequence is formated in another format and for example if the value of select XX_SQ.nextval from dual give 500, the row in database for the index is 1,45487E45.
And I don't know why the index is formatted in depends of my Date format who is not a key and I remove all Oracle constraints on this Date.

I have no exceptions or something else, the row is well in databse but the format of my key is strange, for the Date value is also correct.
Only the KEY is strange...

For example if I don't give a value for the Date, the format of my key is good too.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 12, 2004 8:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Two things:

1) Make *sure* you are using the correct dialect for your database. The dialect Hibernate is using from the configuration it receives is logged during session factory construction...

2) Turn on the info level in log4j for the "net.sf.hibernate.type" logger. This will display the parameters that Hibernate is binding to the prepared statement. Post that information for the insert statements that are getting messed up.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 12, 2004 6:24 pm 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
Yes Steve... I use the good Dialect I use Oracle 8i and I try with Orale Dialect and Dialect 9.
I ll try tomorrow to turn on loggin to see which value is binding.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 3:32 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
Hi all,

I try to turn on net.sf.hibernate.type log but it gives nothing more information about the data who are binding for the prepared statement.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 4:24 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
I succeed to keep binding fields and the log is :

I use java.util.Date in my mapping files and my POJO classes.

10:18:02,175 DEBUG [StringType] - binding 'test' to parameter: 1
10:18:02,175 DEBUG [StringType] - binding 'TestPanel' to parameter: 2
10:18:02,175 DEBUG [TimestampType] - binding '2004-08-13 10:18:02' to parameter: 3
10:18:02,175 DEBUG [IntegerType] - binding '1931' to parameter: 4

The value of the sequence is 1931 and after save if I do a panelBO.getId(), it returns 1931... all seems ok but in database its value is 1,3363E-56

That is so strange, because if I use java.sql.Date, it returns 1931 with the right format :+(

Do you know if a casting operation is done just before creating the request? or if JDBC Driver or Dialect do something wrong?

Any helps will be appreciated about this strange bugs
kind regards


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 5:37 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
I found on this post that this bug comes from Oracle and it's necessary to upgrade with a patch.
Usually I work on Oracle 9 and I have never seen this bug that was I m stupify by this bug:+(
Is it someone could confirm me that the only solution is to apply a patch on Oracle server?

http://forum.hibernate.org/viewtopic.ph ... c&start=15

Thanks in advance.
Kind regards


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 16, 2004 3:46 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
Please, is anybody have an idea about this bug?
This part is very important in my project so if you can help me :+)

thanks in advance, kind regards.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 16, 2004 6:26 am 
Beginner
Beginner

Joined: Mon Aug 16, 2004 6:15 am
Posts: 24
I ran into exactly that bug using Oracle. The problem was fixed by patching up to 8.1.7.4. Reading through the patch notes from Oracle they had the following to say...

Quote:
Updating a NUMBER column and DATE column using any 9.2 OCI client talking to a pre-9.2 server can corrupt the NUMBER column on UPDATE.


Now they only specified OCI, but I had this issue using the thin drivers - the symptom was exactly the same, and this patch defintely fixed the issue.

Happy Hibernating


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 16, 2004 7:55 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
My problem is the Oracle expert of my service said me that is the last version and I have always the bug:(


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 16, 2004 8:04 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
subich wrote:
My problem is the Oracle expert of my service said me that is the last version and I have always the bug:(

And this morning I ask an access to a new instance of Oracle version 9 and I hava always this bug.

Greeting Cobol :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 16, 2004 10:46 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
Sorry to post again but this bug is so ****
Some information that I can find on Internet advise to upgrade Oracle to 8.1.7.4
But I want to know if this bug is knowed with Oracle 9.0.1.1.1.

One another point very strange my change nothing in my code but I add a field in database (NUMBER) and I set this new field in my POJO.
The string insert is ok.
My conclusion is if I have more than 1 NUMBER it's ok but if I have only 1, JDBC driver give strange values to my integer fields.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 16, 2004 11:01 am 
Beginner
Beginner

Joined: Mon Aug 16, 2004 6:15 am
Posts: 24
I think the best people to ask if this bug exists in Oracle 9.0.1.1.1 would be Oracle themselves.

A lot of folks won't get this problem as they'd be using jdbc drivers for the version of the database they are connecting to (of course whether or not those drivers are supported under JDK 1.4 is another matter).

This bug only happened when using a 9.2 and above jdbc driver talking to a (in my case) 8.1.7 database. Using the 8.1.7 jdbc drivers worked fine (but I couldn't use them as they aren't supported under jdk 1.4 iirc).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 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.