-->
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.  [ 11 posts ] 
Author Message
 Post subject: Only the day is retrieved back from MSSQL database
PostPosted: Thu Aug 18, 2005 4:43 pm 
Newbie

Joined: Wed May 25, 2005 11:32 am
Posts: 14
I am using Hibernate 3.0.4 with Mssql database. I am using hbm2java to generate my class files, and also using schema export util come with hibernate to generate sql script to create database tables. My mapping file defines a field as date or timestamp type. The generated class file with this field as java.util.Date type, and database type is datatime. Even through I see hours, minutes and seconds has been correctly write to database. When I try to retrieve the object back, the time only has day in it. Does anyone know how to retrieve the time field up to seconds.



Thanks!


Top
 Profile  
 
 Post subject: Re: Only the day is retrieved back from MSSQL database
PostPosted: Thu Aug 18, 2005 5:08 pm 
Beginner
Beginner

Joined: Thu Feb 17, 2005 9:20 pm
Posts: 36
Location: Vancouver, WA
jfan wrote:
I am using Hibernate 3.0.4 with Mssql database. I am using hbm2java to generate my class files, and also using schema export util come with hibernate to generate sql script to create database tables. My mapping file defines a field as date or timestamp type. The generated class file with this field as java.util.Date type, and database type is datatime. Even through I see hours, minutes and seconds has been correctly write to database. When I try to retrieve the object back, the time only has day in it. Does anyone know how to retrieve the time field up to seconds.



Thanks!


MSSQL does not have separate types for Date and Time. To handle that you should use java.sql.Date to persist Date data and java.sql.Time to persist Time only or java.util.Date to pestist date and time. Either way you will have this types persisted in MS SQL as datetime type. It means you will have date and time parts pestisted. Your code responsibility how to treat each one of them. For example if you need to persist time only use in mappings(POJO) java.sql.Time and use in your java code as a time attribute. Then you should be fine.

_________________
Vasyl Zhabko


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 6:10 pm 
Newbie

Joined: Wed May 25, 2005 11:32 am
Posts: 14
No, I do not want to sepeate date and time. I am having problem display time to user with day, hours, minutes, and seconds. It seems truncate the fields when hibenate query comes back because I can see in the database it is saved with seconds info.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 6:51 pm 
Beginner
Beginner

Joined: Thu Feb 17, 2005 9:20 pm
Posts: 36
Location: Vancouver, WA
jfan wrote:
No, I do not want to sepeate date and time. I am having problem display time to user with day, hours, minutes, and seconds. It seems truncate the fields when hibenate query comes back because I can see in the database it is saved with seconds info.


We are using H3 now and 2.1.x previously. We did not have such a problem so far. Everything works as defined and implemented. I think you are loosing your data somewhere in between Hibernate and your client. Check what you actually read from DB just after Hibernate call. Check what type you have in mapping and what you have actually imported in POJO class.

_________________
Vasyl Zhabko


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 1:17 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 11:06 pm
Posts: 46
A lousy workaround is simply saving the date as long (see java API for Date().getTime()) and rebuild the date object in application code.

_________________
Jason Li
Don't forget to rate:)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 12:30 pm 
Newbie

Joined: Wed May 25, 2005 11:32 am
Posts: 14
Yes, I was looking the createDate right after group object was loaded.

Here is my mapping file and generated class file and generated sql script

<?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="test.AssetGroupVO" table="ASSETGROUP">
<id name="id" type="long" column="ASSETGROUP_ID">
<generator class="native"/>
</id>
<property name="name" type="string" not-null="false" length="255"/>
<property name="type" type="int" not-null="true" length="50"/>
<property name="description" type="string" not-null="false" length="255" />
<property name="createDate" type="timestamp" not-null="true"/>

</class>

</hibernate-mapping>


public class AssetGroupVO implements java.io.Serializable {

// Fields

private Long id;
private String name;
private Integer type;
private String description;
private Date createDate;


......
}

create table ASSETGROUP (
ASSETGROUP_ID numeric(19,0) identity not null,
name varchar(255) null,
type int not null,
description varchar(255) null,
createDate datetime not null,
accountID numeric(19,0) null,
primary key (ASSETGROUP_ID));


Thanks for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 1:08 pm 
Beginner
Beginner

Joined: Thu Feb 17, 2005 9:20 pm
Posts: 36
Location: Vancouver, WA
Take a look what type you have imported in you pojo.

Code:
public class AssetGroupVO implements java.io.Serializable {

// Fields

private Long id;
private String name;
private Integer type;
private String description;
private Date createDate;


......
}


What Date type for createDate? java.sal.Date or java.util.Date? Check if your import is right.

_________________
Vasyl Zhabko


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 12:39 pm 
Newbie

Joined: Wed May 25, 2005 11:32 am
Posts: 14
It is java.util.Date type. This file is generated by hbm2Java task.


Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 12:46 pm 
Regular
Regular

Joined: Mon Aug 22, 2005 1:11 pm
Posts: 50
Location: Pasadena, CA
Have you tried using for the query analyzer that comes with Hibernate 3 and see what you are getting back?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 2:30 pm 
Newbie

Joined: Wed May 25, 2005 11:32 am
Posts: 14
Could you point to me how to run this tool?


Thanks for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 4:43 pm 
Newbie

Joined: Wed May 25, 2005 11:32 am
Posts: 14
I was using both SQuirrel and SQL Server 200 Enterprise manager to view the real databse( Mssql server 2000).Both show createDate to secconds. But from hibernate query only day come out.

Similar thing happens when I do unit test using Hsql.
When I use org.hsqldb.util.DatabaseManager to view createDate, I can only see day without hours, minutes and seconds.

Any help is appreciated! Thanks!


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