-->
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: too dumb for timestamps
PostPosted: Fri Dec 17, 2004 6:32 am 
Beginner
Beginner

Joined: Tue Sep 07, 2004 3:58 am
Posts: 23
Okay, first: Thanx for reading this....

I noticed from another post here that there seems to be an issue with timestamps format mapping from java.util.date and java.sql.timestamp to database timestamps, but.... it seems i just dont get the point.
The case is i save a property of java type java.sql.timestamp which type is determined by reflection (i tried specifying it with type"java.sql.Timestamp" as well ....) it is saved perfectly, but no comparison i do in any HQL queries is doing what its supposed to.
I´m still a hibernate n00b and so the error could be in my hql query as well, but as far as ive seen in other posts it seems to be more a type-problem...
So what do i have to ?
Thanx for any advice...

Schokoladenhase

Hibernate version:
2.1.6
Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
   package="de.zolltek.gtc.data">
   <class name="User" table="user">
      <id name="id" type="string">
         <column name="ID" not-null="true"/>
         <generator class="uuid.hex"></generator>
      </id>
      
      <!-- DATA FIELDS -->
      <property name="login" index="true"/>
      <property name="password" index="true"/>
       <property name="sprache"/>
      
      <!-- FIELDS REQUIRED FOR HISTORIZABILISATION -->
       <property name="recnum"/>
      <property name="wer_in"/>
      <property name="wer_out"/>
       <property name="von"/>
      <property name="bis"/>
      
      <!--  RELATIONAL FIELDS -->
      <!--  reflecting the 1:1 relation to person -->
      <property name="personrecnum"/>
   </class>
</hibernate-mapping>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
   package="de.zolltek.gtc.data">
   <class name="Person" table="person">
      <id name="id" type="string">
         <column name="ID" not-null="true"/>
         <generator class="uuid.hex"></generator>
      </id>
      
      <!-- DATA FIELDS -->
      <property name="anrede"/>
      <property name="email"/>
      <property name="fax"/>
       <property name="telefon"/>
       <property name="vorname"/>
       <property name="name"/>
       
       <!-- FIELDS REQUIRED FOR HISTORIZABILISATION -->
       <property name="recnum" not-null="true" index="rectime_idx"/>
      <property name="wer_in"/>
      <property name="wer_out"/>
       <property name="von"/>
      <property name="bis"/>

   </class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
person = (Person) s.createQuery("select p " +
                  "from Person p " +
                  "where p.recnum='"+personrecnum+"' "
               +ServletContext.timeCriteria("")
               )
                  .list()
                  .get(0);

....with ServletContext.timeCriteria("") being:

public static String timeCriteria(String activeuserrecnum) {
      return new String(" and '"+getWishedTime(activeuserrecnum)+"' between " +
            "bis and von");
   }

public static Timestamp getWishedTime(String userrecnum) {
      // TODO Make map with userwishedtimes
      return new Timestamp(System.currentTimeMillis());
   }

Full stack trace of any exception that occurs:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
10:38:44,090 INFO [STDOUT] at java.util.ArrayList.RangeCheck(ArrayList.java:507)
10:38:44,090 INFO [STDOUT] at java.util.ArrayList.get(ArrayList.java:324)
10:38:44,090 INFO [STDOUT] at de.zolltek.gtc.data.User.onLoad(User.java:225)
10:38:44,090 INFO [STDOUT] at net.sf.hibernate.impl.SessionImpl.initializeEnti......

Name and version of the database you are using:
MySQL 3.2.3

The generated SQL (show_sql=true):
Code:
select user0_.ID as ID, user0_.login as login, user0_.password as password, user0_.sprache as sprache, user0_.recnum as recnum, user0_.wer_in as wer_in, user0_.wer_out as wer_out, user0_.von as von, user0_.bis as bis, user0_.personrecnum as personr10_ from user user0_ where (user0_.login='Max' )and(user0_.password='Moritz' )and(bis>'2004-12-17 10:38:43.609' )and(von<'2004-12-17 10:38:43.609' )
select person0_.ID as ID, person0_.anrede as anrede, person0_.email as email, person0_.fax as fax, person0_.telefon as telefon, person0_.vorname as vorname, person0_.name as name, person0_.recnum as recnum, person0_.wer_in as wer_in, person0_.wer_out as wer_out, person0_.von as von, person0_.bis as bis from person person0_ where (person0_.recnum='2c90a5ee00dc27380100dcaf72d401a7' )and(bis>'2004-12-17 10:38:44.009' )and(von<'2004-12-17 10:38:44.009' )

_________________
People keep asking me if i know Tyler Durden....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 17, 2004 6:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Don't use String concatenation for building your queries, use parameter placeholders.


Top
 Profile  
 
 Post subject: Thanx
PostPosted: Fri Dec 17, 2004 7:44 am 
Beginner
Beginner

Joined: Tue Sep 07, 2004 3:58 am
Posts: 23
Thanx.
I changed
Code:
person = (Person) s.createQuery("select p " +
                  "from Person p " +
                  "where p.recnum='"+personrecnum+"' "
               +ServletContext.timeCriteria("")
               )
                  .list()
                  .get(0);


into

Code:
List tmp= s.find(
                  "from Person as p " +
                  "where p.recnum=? and ? between p.von and p.bis",new Object[] {recnum,ServletContext.getWishedTime("")},new Type[]{Hibernate.STRING,Hibernate.TIMESTAMP}
               );
           person = (Person) tmp.get(0);

_________________
People keep asking me if i know Tyler Durden....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 17, 2004 8:10 am 
Beginner
Beginner

Joined: Tue Sep 07, 2004 3:58 am
Posts: 23
ups... forgot to mention:
Problem persists
:(

_________________
People keep asking me if i know Tyler Durden....


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.