-->
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.  [ 2 posts ] 
Author Message
 Post subject: Date query by using Buddhist Era(BE) fail
PostPosted: Tue Jun 21, 2005 1:32 am 
Newbie

Joined: Tue Jun 21, 2005 1:09 am
Posts: 2
Hi I'm having problem with Hibernate about date query. I try to query a record and then try to re-query with the criteria by using the data found previously. But there's no result returned. I think the year return is not match with the regional setting in my machine, coz I'm using Buddhist era (year 2005 = 2548 BE). The data type in the DB is stored as DATETIME.

Hibernate version: 2.1.7

Mapping documents:

Code:
<hibernate-mapping>
   <class name="ebiz.sdc.fraud.model.FraudAttempt" table="EBMS_FRAUD_ATTEMPTS">
      <composite-id>
         <key-property name="action" column="action"
            type="java.lang.String" length="30">
         </key-property>
         <key-property name="actionDate" column="action_date"
            type="java.util.Date">
         </key-property>
...
...



Code between sessionFactory.openSession() and session.close():

Code:
FraudAttemptDao.java

   public Collection findAllFraudAttempts() throws FindingException {
      FraudAttempt fraudAttempt = new FraudAttempt();
      return findFraudAttempts(fraudAttempt);
   }

   public Collection findFraudAttempts(FraudAttempt fraudAttempt) throws FindingException {
      Collection result = null;
      try {
         Session s = new Configuration().configure().buildSessionFactory().openSession();
         Criteria c = s.createCriteria(FraudAttempt.class);
         if (fraudAttempt.getAction() != null && !"".equals(fraudAttempt.getAction())) {
            c.add(Expression.like("action", fraudAttempt.getAction()));
         }
         if (fraudAttempt.getActionDate() != null) {
            c.add(Expression.eq("actionDate", fraudAttempt.getActionDate()));
         }
         c.addOrder(Order.asc("actionDate"));
         
         result = c.list();
         s.close();
      } catch (HibernateException e) {
         throw new FindingException(e);
      }
      return result;
   }



Code:
FraudAttemptTest.java

      FraudAttemptDao dao = new FraudAttemptDao();
      try {
         Collection c1 = dao.findAllFraudAttempts(1, 3);
         FraudAttempt f1 = null;
         if (c1 != null && c1.size() > 0) {
            f1 = (FraudAttempt)c1.iterator().next();
            System.out.println("f1 : " + f1.getActionDate());
         }
         
         FraudAttempt ftemp = f1;
         Collection c2 = dao.findFraudAttempts(ftemp, 1, 1);
         FraudAttempt f2 = null;
         if (c2 != null && c2.size() > 0) {
            f2 = (FraudAttempt)c2.iterator().next();
            System.out.println("f2 : " + f2.getActionDate());
         }
         
         if (f1 != null && f2 != null) {
            assertEquals(f1.getMemo(), f2.getMemo());
         }

Name and version of the database you are using: Oracle9i 9.0.2


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 21, 2005 1:36 am 
Newbie

Joined: Tue Jun 21, 2005 1:09 am
Posts: 2
I have to fix by using the following code.

Code:
FraudAttemptDao.java

...
...
         if (fraudAttempt.getActionDate() != null) {
            SimpleDateFormat dfTH = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss", new Locale("th", "TH"));
            SimpleDateFormat dfUS = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss", Locale.US);
            try {
               c.add(Expression.eq("actionDate", dfTH.parse(dfUS.format(fraudAttempt.getActionDate()))));
            } catch (ParseException e) {
               e.printStackTrace();
            }
         }
...
...


Hibernate is used by developers worldwide. I don't know whether there'r anybody meet with this kind of problem. As I search the web, I still havn't found any solution yet.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.