-->
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.  [ 4 posts ] 
Author Message
 Post subject: Oracle 10g and Timestamp
PostPosted: Mon Jun 05, 2006 12:38 pm 
Newbie

Joined: Wed May 25, 2005 8:28 am
Posts: 18
Hi everybody,

I was using oracle 9i and hibernate 3.1 with the following code:

Code:
Query qPub = sessApolo.createQuery("select m from MovimentoProcesso m where m.codigoProcesso = :codigoProcesso and m.codigoSecao = :codigoSecao and m.dataMovimento = :dataMovimento");
            qPub.setInteger("codigoProcesso",sp.getCodigoProcesso());
            qPub.setInteger("codigoSecao",sp.getCodigoSecao());
            qPub.setTimestamp("dataMovimento",sp.getDataMovimento());
            Iterator iPub = qPub.iterate();


It was working well.

So, my database was upgraded to oracle 10g. The query now does not return anything.

Why?

My object mapping is:

Code:
<?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="br.gov.trf2.jfes.apolo.processo.MovimentoProcesso" table="apoloes.movimento">
   <composite-id>
      <key-property name="codigoSecao" type="int">
         <column name="CODSECAO" not-null="true"/>
      </key-property>
      <key-property name="codigoProcesso" type="int">
         <column name="CODDOC" not-null="true"/>
      </key-property>
      <key-property name="dataMovimento" type="java.sql.Timestamp">
         <column name="DTHRMOV" not-null="true"/>
      </key-property>
   </composite-id>

   <property name="observacao" type="java.lang.String" >
      <column name="OBS" length="250" not-null="false"/>
   </property>

   <many-to-one name="fase"
      class="br.gov.trf2.jfes.apolo.processo.FaseProcesso"
      insert="false"
      update="false"
      outer-join="false"
      not-null="false" not-found="ignore">
      <column name="CODSECAO"/>
      <column name="CODFASE"/>
   </many-to-one>

   <many-to-one name="processo"
      class="br.gov.trf2.jfes.apolo.processo.Processo"
      insert="false"
      update="false"
      outer-join="false"
      not-null="false" not-found="ignore">
      <column name="CODSECAO"/>
      <column name="CODDOC"/>
   </many-to-one>

   <many-to-one name="complemento1"
      class="br.gov.trf2.jfes.apolo.processo.Complemento"
      insert="false"
      update="false"
      outer-join="false"
      not-null="false" not-found="ignore">
      <column name="CODSECAO"/>
      <column name="CODCOMPL1"/>
   </many-to-one>

   <many-to-one name="texto"
      class="br.gov.trf2.jfes.apolo.processo.MovimentoTexto"
      insert="false"
      update="false"
      outer-join="false"
      not-null="false" not-found="ignore">
      <column name="CODSECAO"/>
      <column name="CODDOC"/>
      <column name="DTHRMOV"/>
   </many-to-one>
</class>
</hibernate-mapping>
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 05, 2006 1:07 pm 
Regular
Regular

Joined: Mon May 22, 2006 2:30 pm
Posts: 74
It looks like you are querying using a timestamp value as part of the criteria. That is usually a bad idea. What you are most likely encountering is a change in driver behaviour. If the timestamp is being mapped to a java.sql.Date instead of a java.util.Date or java.util.Timestamp, all the hour-minutes-seconds part of the timestamp will be removed. There are a lot of issues with databases and timestamps mapping to Java. Or, it could be the difference between the java.util.Date and java.util.Timestamp, since the latter supports nanosecond precision. So you are most likely losing some precision in the translation from java type to db type, or vice versa. But, it's very difficult to say since you have not provided much information. This would be a more appropriate question to ask in a Oracle forum, where someone might be more familiar with the precise difference between the two versions.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 05, 2006 1:33 pm 
Newbie

Joined: Wed May 25, 2005 8:28 am
Posts: 18
I think this is a JDBC Driver problem:

The following code functions in 9i but not in 10g

Code:
         Class.forName("oracle.jdbc.driver.OracleDriver");
         Connection con = DriverManager.getConnection("jdbc:oracle:thin:@reia.sjes.gov.br:1521:jfes2","INTRANET","");

         PreparedStatement stmt = con.prepareStatement("select DTHRMOV from apoloes.movimentotexto movimentot0_ " +
               "where movimentot0_.CODSECAO=:codsecao " +
               "and movimentot0_.CODDOC=:coddoc " +
               "and movimentot0_.DTHRMOV=:data");

         stmt.setInt(1,50);
         stmt.setInt(2,502914);
         Timestamp t = new Timestamp(106,04,16,17,24,0,0);
         stmt.setTimestamp(3,t);

         ResultSet r = stmt.executeQuery();
         while(r.next()){
            System.out.println(r.getTimestamp(1));
         }

         con.close();


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 05, 2006 3:01 pm 
Regular
Regular

Joined: Mon May 22, 2006 2:30 pm
Posts: 74
I have run into quite a few problems with DB dates/timestamps on various projects. On the last one, a query with a date constraint worked perfectly on SQL Server, but failed to work on Oracle 9. Apparently the SQL Server JDBC driver was returning the results with the hours-minutes-seconds as a java.util.Date, while the Oracle driver was returning a java.sql.Date, and dropping the time portion. Although Oracle was technically more correct according to the JDBC spec, it was less helpful. I determined this by stopping in the debugger and examing the data types. You might want to make sure the results are instances of what you are actually expecting. It could be there was some error introduced in the 10g driver, and it's not really a timestamp with hours-minutes-seconds. At least you could compare the values going in and coming back by running another query that will cause the target row to be returned by 10g, and then getting the timestamp column value. Or something like that.


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