Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] java.util.GregorianCalendar cannot be cast to java.util.Date
[Teneo] java.util.GregorianCalendar cannot be cast to java.util.Date [message #663555] Tue, 05 April 2011 15:33 Go to next message
Fer Missing name is currently offline Fer Missing nameFriend
Messages: 24
Registered: September 2009
Junior Member
Dear all,

I would like to persist java.util.GregorianCalendar values in my database using Teneo and Hibernate. Is it possible?

I am getting the following error:
java.lang.ClassCastException: java.util.GregorianCalendar cannot be cast to java.util.Date
	at org.hibernate.type.descriptor.java.JdbcTimestampTypeDescriptor$TimestampMutabilityPlan.deepCopyNotNull(JdbcTimestampTypeDescriptor.java:46)
	at org.hibernate.type.descriptor.java.MutableMutabilityPlan.deepCopy(MutableMutabilityPlan.java:58)
	at org.hibernate.type.AbstractStandardBasicType.deepCopy(AbstractStandardBasicType.java:313)
	at org.hibernate.type.AbstractStandardBasicType.deepCopy(AbstractStandardBasicType.java:309)
	at org.hibernate.type.TypeHelper.deepCopy(TypeHelper.java:68)
	at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:302)
	at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203)
	at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:143)
	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
	at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:685)
	at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:677)
	at org.hibernate.engine.CascadingAction$5.cascade(CascadingAction.java:252)
	at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:392)
	at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:335)
	at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:204)
	at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:425)
	at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:362)
	at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:338)
	at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:204)
	at org.hibernate.engine.Cascade.cascade(Cascade.java:161)
	at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:475)
	at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:353)
	at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203)
	at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:143)
	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
	at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
	at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
	at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:713)
	at org.hibernate.impl.SessionImpl.save(SessionImpl.java:701)
	at org.hibernate.impl.SessionImpl.save(SessionImpl.java:697)


Is it necessary to change the following values?
* PersistenceOptions.DEFAULT_TEMPORAL_VALUE or
* PersistenceOptions.USER_XSDDATE_TYPE
* ...

Thanks in advance,

Fernando
Re: [Teneo] java.util.GregorianCalendar cannot be cast to java.util.Date [message #663579 is a reply to message #663555] Tue, 05 April 2011 16:47 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Fer,
To store a gregorian calendar you have to make use of a specific user type. Teneo automatically does this for xsd
date/datetime. But if your model is not derived from a xsd then Teneo can't discover this, so you explicitly have to set
the user type.

You can use the user types provided by Teneo:
org.eclipse.emf.teneo.hibernate.mapping.XSDDate
org.eclipse.emf.teneo.hibernate.mapping.XSDDateTime

You can set the user type as an annotation (in the EDataType for example):
@TypeDef(name="GregDate", typeClass="org.eclipse.emf.teneo.hibernate.mapping.XSDDate")

gr. Martin

On 04/05/2011 05:33 PM, Fer wrote:
> Dear all,
>
> I would like to persist java.util.GregorianCalendar values in my database using Teneo and Hibernate. Is it possible?
>
> I am getting the following error:
>
> java.lang.ClassCastException: java.util.GregorianCalendar cannot be cast to java.util.Date
> at
> org.hibernate.type.descriptor.java.JdbcTimestampTypeDescript or$TimestampMutabilityPlan.deepCopyNotNull(JdbcTimestampType Descriptor.java:46)
>
> at org.hibernate.type.descriptor.java.MutableMutabilityPlan.dee pCopy(MutableMutabilityPlan.java:58)
> at org.hibernate.type.AbstractStandardBasicType.deepCopy(Abstra ctStandardBasicType.java:313)
> at org.hibernate.type.AbstractStandardBasicType.deepCopy(Abstra ctStandardBasicType.java:309)
> at org.hibernate.type.TypeHelper.deepCopy(TypeHelper.java:68)
> at org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:302)
> at org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:203)
> at org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:143)
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:210)
>
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
> at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl. java:685)
> at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :677)
> at org.hibernate.engine.CascadingAction$5.cascade(CascadingActi on.java:252)
> at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:392)
> at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java :335)

> at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:20 4)
> at org.hibernate.engine.Cascade.cascadeCollectionElements(Casca de.java:425)
> at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java: 362)
> at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java :338)
> at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:20 4)
> at org.hibernate.engine.Cascade.cascade(Cascade.java:161)
> at org.hibernate.event.def.AbstractSaveEventListener.cascadeAft erSave(AbstractSaveEventListener.java:475)
> at org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:353)
> at org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:203)
> at org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:143)
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:210)
>
> at org.hibernate.event.def.DefaultSaveEventListener.saveWithGen eratedOrRequestedId(DefaultSaveEventListener.java:56)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
> at org.hibernate.event.def.DefaultSaveEventListener.performSave OrUpdate(DefaultSaveEventListener.java:50)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
> at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:713 )
> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:701)
> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:697)
>
>
> Is it necessary to change the following values?
> * PersistenceOptions.DEFAULT_TEMPORAL_VALUE or * PersistenceOptions.USER_XSDDATE_TYPE
> * ...
>
> Thanks in advance,
>
> Fernando


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] java.util.GregorianCalendar cannot be cast to java.util.Date [message #663714 is a reply to message #663579] Wed, 06 April 2011 09:55 Go to previous messageGo to next message
Fer Missing name is currently offline Fer Missing nameFriend
Messages: 24
Registered: September 2009
Junior Member
Hello Martin,

Thank you very much for your response.

I would like to set the value from the *.persistence.xml file, I'm trying to set it as follows:


<eclass name="EngineeringAnnotationItem">
	<property name="issueDate">
	        <external> org.eclipse.emf.teneo.hibernate.mapping.XSDDate </external> 
	</property>			
</eclass>


But I getting an error.

org.eclipse.emf.teneo.annotations.xml.ParseXMLAnnotationsExc eption: Cannot handle element <external>

What would be the correct format?

Thanks in advance,

Fernando
Re: [Teneo] java.util.GregorianCalendar cannot be cast to java.util.Date [message #663737 is a reply to message #663714] Wed, 06 April 2011 11:09 Go to previous messageGo to next message
Fer Missing name is currently offline Fer Missing nameFriend
Messages: 24
Registered: September 2009
Junior Member
Hello Martin,

I have modified my *.persistence.xml file as follows:

<eclass name="EngineeringAnnotationItem">
	<property name="issueDate">
		<type type="org.eclipse.emf.teneo.hibernate.mapping.XSDDate"/> 
	</property>			
</eclass>


But now I get the following error:

java.lang.ClassCastException: java.util.GregorianCalendar cannot be cast to javax.xml.datatype.XMLGregorianCalendar

What do you think?

Best Regards,

Fernando
Re: [Teneo] java.util.GregorianCalendar cannot be cast to java.util.Date [message #663761 is a reply to message #663737] Wed, 06 April 2011 12:35 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Fer,
Ha okay, the XSDDate user type provided by Teneo uses the javax.xml.datatype.XMLGregorianCalendar. So in this case you
need to create your own user type which can handle java.util.GregorianCalendar, you can use the XSDDate user type as an
example for this.

gr. Martin

On 04/06/2011 01:09 PM, Fer wrote:
> Hello Martin,
>
> I have modified my *.persistence.xml file as follows:
>
>
> <eclass name="EngineeringAnnotationItem">
> <property name="issueDate">
> <type type="org.eclipse.emf.teneo.hibernate.mapping.XSDDate"/> </property>
> </eclass>
>
>
> But now I get the following error:
>
> java.lang.ClassCastException: java.util.GregorianCalendar cannot be cast to javax.xml.datatype.XMLGregorianCalendar
>
> What do you think?
>
> Best Regards,
>
> Fernando
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] java.util.GregorianCalendar cannot be cast to java.util.Date [message #663816 is a reply to message #663761] Wed, 06 April 2011 14:56 Go to previous message
Fer Missing name is currently offline Fer Missing nameFriend
Messages: 24
Registered: September 2009
Junior Member
Hello Martin,

Thank you very much. I have already successfully implemented my UserType.

Best Regards,

Fernando
Previous Topic:Generated edit code and Dynamic EMF
Next Topic:jpa.teno-Annotation => persistence-mapping-hibernate
Goto Forum:
  


Current Time: Tue Oct 22 11:20:41 GMT 2019

Powered by FUDForum. Page generated in 0.02429 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top