-->
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.  [ 5 posts ] 
Author Message
 Post subject: UserType implementation not inserting proper Date format.
PostPosted: Sun Nov 07, 2004 11:35 pm 
Newbie

Joined: Sun Nov 07, 2004 9:58 pm
Posts: 6
I want to map referenced object(Spec) in main Object as User Type. I created main Object(Request) and it as a property column EXPIRE_TIMESTAMP which maps to
@hibernate.property column="EXPIRE_TIMESTAMP" type="com.SpecHibernatePersistenceType" inside Request object.

I implemeted a UserType to map between Date in SpecHibernatePersistenceType and Date column in Oracle.

The Date inserted in oracle does not contain time, it only contains date part(ex:11/07/04, no 6:23:43 PM part)

For example, say I have a managed object like this:

public class Request
{
....
private Spec spec;
....
}


which is mapped like this

....
@hibernate.property column="EXPIRE_TIMESTAMP" type="com.SpecHibernatePersistenceType"

....

and UserType : SpecHibernatePersistenceType
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException
{
if (value == null) {
st.setNull(index, Types.DATE);
} else {
st.setDate(index, new java.sql.Date(((Spec) value.getExpireTimeStamp().getTime()) );
}
}

Iam using java.sql.Date here because my Spec member variable expireTimestamp is of java.util.Date type.
public class Spec
{
private java.util.Date expireTimestamp;
}

Thanks,
Kyama

Hibernate version:
2.1.6
Mapping documents:
n/a
Code between sessionFactory.openSession() and session.close():
n/a
Full stack trace of any exception that occurs:
n/a
Name and version of the database you are using:
Oracle 9i
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 08, 2004 4:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
use setTimestamp


Top
 Profile  
 
 Post subject: UserType implementation not inserting proper Date format.
PostPosted: Mon Nov 08, 2004 1:36 pm 
Newbie

Joined: Sun Nov 07, 2004 9:58 pm
Posts: 6
where do you want to use setTimeStamp(). Iam already using in Spec.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 08, 2004 1:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
in nullSafeSet - please read the JDBC API


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 09, 2004 3:39 pm 
Newbie

Joined: Sun Nov 07, 2004 9:58 pm
Posts: 6
What is wrong with nullSafeSet implementation


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