-->
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.  [ 6 posts ] 
Author Message
 Post subject: Correct Annotation for Calendar
PostPosted: Fri Jan 27, 2006 9:10 pm 
Newbie

Joined: Wed Nov 16, 2005 11:52 am
Posts: 6
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1.1, Hibernate Annotations:3.1beta8

I am switching from mapping files to annotations.

While mapping a Calendar field as follows I get a ClassCastException.

@Temporal(TemporalType.TIMESTAMP)
@Column(name="startDate", nullable = false)
public Calendar getStartDate() {
return startDate;
}

what is the correct annotation to be used?

thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 10:05 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
and the stacktrace is.
As we say in French, The question template is not here for the dogs

_________________
Emmanuel


Top
 Profile  
 
 Post subject: StackTrace with code...
PostPosted: Wed Mar 01, 2006 3:29 pm 
Newbie

Joined: Wed Mar 09, 2005 12:36 am
Posts: 12
I'm having the same problem... and since he/she never responded with any more info, let me. Thanks in advance for help.

DB: MySQL 5.0.18
Hibernate versions:
hibernate-3.1.2.tar.gz
hibernate-annotations-3.1beta8.tar.gz

...
protected Calendar calendarProperty;
@Column(name="calendar_property")
@Temporal
public Calendar getCalendarProperty() {
return calendarProperty;
}
...

...
obj.setCalendarProperty(new GregorianCalendar());

//create the object
Transaction tx = super.session.beginTransaction();
super.session.saveOrUpdate(ato);
Integer atoId = ato.getId();
super.assertNotNull(atoId);
tx.commit();
...


StackTrace:

Testcase: testAllTypesObjectHibernateCreate took 1.36 sec
Caused an ERROR
java.util.GregorianCalendar
java.lang.ClassCastException: java.util.GregorianCalendar
at org.hibernate.type.TimestampType.deepCopyNotNull(TimestampType.java:66)
at org.hibernate.type.MutableType.deepCopy(MutableType.java:25)
at org.hibernate.type.TypeFactory.deepCopy(TypeFactory.java:323)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:255)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:101)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:531)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:519)
at com.virtuas.hibfun.domain.hibernate.AllTypesObjectHibernateTest.testAllTypesObjectHibernateCreate(AllTypesObjectHibernateTest.java:104)



I've tried it by explicitly specifiying the 3 possible TemporalType's to no avail. I'm generating the ddl, and that is occuring correctly (TemporalType.DATE to MySql date, TemporalType.TIME to MySql time, TemporalType.TIMESTAMP to MySql datetime).

Here is the ddl:

create table hibfun_all_types (
id integer not null auto_increment,
calendar_property datetime,
primary key (id)
);


Top
 Profile  
 
 Post subject: Fixed it with...
PostPosted: Wed Mar 01, 2006 3:48 pm 
Newbie

Joined: Wed Mar 09, 2005 12:36 am
Posts: 12
protected Calendar calendarProperty;
@Column(name="calendar_property")
@Temporal(TemporalType.TIMESTAMP)
@org.hibernate.annotations.Type(type="calendar")
public Calendar getCalendarProperty() {
return calendarProperty;
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 12:56 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Thanks, that's fixed
http://opensource.atlassian.com/project ... se/ANN-266

_________________
Emmanuel


Top
 Profile  
 
 Post subject: No problem.
PostPosted: Thu Mar 02, 2006 5:31 pm 
Newbie

Joined: Wed Mar 09, 2005 12:36 am
Posts: 12
Wow... pretty quick turnaround. Good stuff. Thank you.


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