Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo][Hibernate] ClassCastException:(java.util.GregorianCalendar cannot be cast to java.util.Date)
[Teneo][Hibernate] ClassCastException: [message #831894] Thu, 29 March 2012 13:53 Go to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
Hello guys,

i created an ecore model which defines an JCalendar from java.util.Calendar
in my ecore its this:
Quote:
<eClassifiers xsi:type="ecore:EDataType" name="JCalendar" instanceClassName="java.util.Calendar"/>

when i generate my model, everything is fine.
when i try the quickstart example with my model everything boots up fine, i even get the mapping logged to console but then it gets followed by this exception
Quote:
Exception in thread "main" 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:129)
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)
at lumo.licensing.runtime.QuickStart.doQuickStart(QuickStart.java:111)
at lumo.licensing.runtime.QuickStart.main(QuickStart.java:35)


any help wellcome!

thanks in advance
lumo

PS: i've searched the forum, but did not find the answer i am searching for.

[Updated on: Thu, 29 March 2012 14:15]

Report message to a moderator

Re: [Teneo][Hibernate] ClassCastException: [message #832203 is a reply to message #831894] Thu, 29 March 2012 22:36 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
It would probably help to see the generate mapping.

Tom

Am 29.03.12 09:53, schrieb Ludwig Moser:
> Hello guys,
>
> i created an ecore model which defines an JCalendar from java.util.Calendar
> in my ecore its this:
> Quote:
>> <eClassifiers xsi:type="ecore:EDataType" name="JCalendar"
>> instanceClassName="java.util.Calendar"/>
>
> NOTE: i do know that i could exchange it to date in THIS case, but in my
> real application i store not only the date in the calender. it also
> contains hout/minutes/seconds...
> when i generate my model, everything is fine.
> when i try the quickstart example with my model everything boots up
> fine, i even get the mapping logged to console but then it gets followed
> by this exception
> Quote:
>> Exception in thread "main" 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:129)
>>
>> 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)
>> at
>> lumo.licensing.runtime.QuickStart.doQuickStart(QuickStart.java:111)
>> at lumo.licensing.runtime.QuickStart.main(QuickStart.java:35)
>
>
> any help wellcome!
>
> thanks in advance
> lumo
>
> PS: i've searched the forum, but did not find the answer i am searching
> for.
Re: [Teneo][Hibernate] ClassCastException: [message #832401 is a reply to message #832203] Fri, 30 March 2012 05:07 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
here is my generated mapping and the ecore.
actually its only my first test to find out how stuff works.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping auto-import="false">
	<class name="lumo.licensing.impl.CustomerImpl" entity-name="Customer" abstract="false" lazy="false" discriminator-value="Customer" table="`customer`">
		<meta attribute="eclassName" inherit="false">Customer</meta>
		<meta attribute="epackage" inherit="false">http://www.biooffice.at/lumo/licensing</meta>
		<id type="long" name="e_id" column="e_id" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler">
			<meta attribute="syntheticId" inherit="false">true</meta>
			<generator class="native"/>
		</id>
		<discriminator type="string">
			<column name="`dtype`" index="customerdtype" length="255" not-null="true"/>
		</discriminator>
		<version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
			<meta attribute="syntheticVersion" inherit="false">true</meta>
		</version>
		<list name="licenses" lazy="true" cascade="all,delete-orphan">
			<key update="true" foreign-key="customer_licenses">
				<column name="`customer_licenses_e_id`" unique="false"/>
			</key>
			<list-index column="`customer_licenses_idx`"/>
			<one-to-many entity-name="License"/>
		</list>
		<property name="registeredTo" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
			<column not-null="false" unique="false" name="`registeredto`"/>
		</property>
		<property name="email" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
			<column not-null="false" unique="false" name="`email`"/>
		</property>
		<property name="phone" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
			<column not-null="false" unique="false" name="`phone`"/>
		</property>
	</class>
	<class name="lumo.licensing.impl.LicenseImpl" entity-name="License" abstract="false" lazy="false" discriminator-value="License" table="`license`">
		<meta attribute="eclassName" inherit="false">License</meta>
		<meta attribute="epackage" inherit="false">http://www.biooffice.at/lumo/licensing</meta>
		<id type="long" name="e_id" column="e_id" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler">
			<meta attribute="syntheticId" inherit="false">true</meta>
			<generator class="native"/>
		</id>
		<discriminator type="string">
			<column name="`dtype`" index="licensedtype" length="255" not-null="true"/>
		</discriminator>
		<version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
			<meta attribute="syntheticVersion" inherit="false">true</meta>
		</version>
		<property name="productId" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
			<column not-null="false" unique="false" name="`productid`"/>
		</property>
		<property name="mac" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
			<column not-null="false" unique="false" name="`mac`"/>
		</property>
		<property name="activated" lazy="false" insert="true" update="true" not-null="false" unique="false" type="timestamp">
			<column not-null="false" unique="false" name="`activated`"/>
		</property>
	</class>
</hibernate-mapping>


from this ecore file
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="licensing"
    nsURI="http://www.biooffice.at/lumo/licensing" nsPrefix="LLic">
  <eClassifiers xsi:type="ecore:EClass" name="Customer">
    <eStructuralFeatures xsi:type="ecore:EReference" name="licenses" lowerBound="1"
        upperBound="-1" eType="#//License" containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="registeredTo" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="email" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="phone" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="License">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="productId" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="mac" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="activated" eType="#//JCalendar"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EDataType" name="JCalendar" instanceClassName="java.util.Calendar"/>
</ecore:EPackage>
Re: [Teneo][Hibernate] ClassCastException: [message #832490 is a reply to message #832401] Fri, 30 March 2012 07:55 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Ludwig,
EMF uses the gregoriancalendar for date times, these are not handled automatically by hibernate. Teneo prevents issues
here by setting a hibernate user type for these fields (date, datetime and time):
org.eclipse.emf.teneo.hibernate.mapping.XSDDate
org.eclipse.emf.teneo.hibernate.mapping.XSDDateTime
org.eclipse.emf.teneo.hibernate.mapping.XSDDateTime

But only if the type is a date/time type from the XMLTypePackage from ecore. This is not the case in your model it seems.
So I guess the best thing you can do is use a java.util.Date as the instance class of the data type. Then it should work
fine. Would this work?
Another solution is to create your own hibernate usertype and annotate the efeature with the correct annotation. Here is
an example (for another case) of setting the user type through a separate xml file:
http://wiki.eclipse.org/Teneo/Hibernate/ModelRelational/Association_Mapping#Storing_references_to_Ecore_Model_Elements
to use this separate xml file:
http://wiki.eclipse.org/Teneo/Hibernate/ModelRelational/Annotations_Format#JPA_Annotations_in_XML

gr. Martin

On 03/30/2012 07:08 AM, Ludwig Moser wrote:
> here is my generated mapping and the ecore.
> actually its only my first test to find out how stuff works.
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
>
> <hibernate-mapping auto-import="false">
> <class name="lumo.licensing.impl.CustomerImpl" entity-name="Customer" abstract="false" lazy="false"
> discriminator-value="Customer" table="`customer`">
> <meta attribute="eclassName" inherit="false">Customer</meta>
> <meta attribute="epackage" inherit="false">http://www.biooffice.at/lumo/licensing</meta>
> <id type="long" name="e_id" column="e_id"
> access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler">
> <meta attribute="syntheticId" inherit="false">true</meta>
> <generator class="native"/>
> </id>
> <discriminator type="string">
> <column name="`dtype`" index="customerdtype" length="255" not-null="true"/>
> </discriminator>
> <version name="e_version" column="e_version"
> access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
> <meta attribute="syntheticVersion" inherit="false">true</meta>
> </version>
> <list name="licenses" lazy="true" cascade="all,delete-orphan">
> <key update="true" foreign-key="customer_licenses">
> <column name="`customer_licenses_e_id`" unique="false"/>
> </key>
> <list-index column="`customer_licenses_idx`"/>
> <one-to-many entity-name="License"/>
> </list>
> <property name="registeredTo" lazy="false" insert="true" update="true" not-null="false" unique="false"
> type="java.lang.String">
> <column not-null="false" unique="false" name="`registeredto`"/>
> </property>
> <property name="email" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
> <column not-null="false" unique="false" name="`email`"/>
> </property>
> <property name="phone" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
> <column not-null="false" unique="false" name="`phone`"/>
> </property>
> </class>
> <class name="lumo.licensing.impl.LicenseImpl" entity-name="License" abstract="false" lazy="false"
> discriminator-value="License" table="`license`">
> <meta attribute="eclassName" inherit="false">License</meta>
> <meta attribute="epackage" inherit="false">http://www.biooffice.at/lumo/licensing</meta>
> <id type="long" name="e_id" column="e_id"
> access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler">
> <meta attribute="syntheticId" inherit="false">true</meta>
> <generator class="native"/>
> </id>
> <discriminator type="string">
> <column name="`dtype`" index="licensedtype" length="255" not-null="true"/>
> </discriminator>
> <version name="e_version" column="e_version"
> access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
> <meta attribute="syntheticVersion" inherit="false">true</meta>
> </version>
> <property name="productId" lazy="false" insert="true" update="true" not-null="false" unique="false"
> type="java.lang.String">
> <column not-null="false" unique="false" name="`productid`"/>
> </property>
> <property name="mac" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
> <column not-null="false" unique="false" name="`mac`"/>
> </property>
> <property name="activated" lazy="false" insert="true" update="true" not-null="false" unique="false" type="timestamp">
> <column not-null="false" unique="false" name="`activated`"/>
> </property>
> </class>
> </hibernate-mapping>
>
>
> from this ecore file
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="licensing"
> nsURI="http://www.biooffice.at/lumo/licensing" nsPrefix="LLic">
> <eClassifiers xsi:type="ecore:EClass" name="Customer">
> <eStructuralFeatures xsi:type="ecore:EReference" name="licenses" lowerBound="1"
> upperBound="-1" eType="#//License" containment="true"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="registeredTo" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="email" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="phone" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="License">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="productId" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="mac" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="activated" eType="#//JCalendar"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EDataType" name="JCalendar" instanceClassName="java.util.Calendar"/>
> </ecore:EPackage>
>


--

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@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Teneo][Hibernate] ClassCastException: [message #832565 is a reply to message #832490] Fri, 30 March 2012 09:39 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
i'm sorry but i do not understand how i can integrate this into my QuickStart example.
my current code (of my application) is using Calendar everywhere instead of Date (although it could be converted)
Re: [Teneo][Hibernate] ClassCastException: [message #832590 is a reply to message #832565] Fri, 30 March 2012 10:16 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Ludwig,
Hmm I see now that hibernate has a type called calendar, which I can use in the mapping. Can you enter a bugzilla to
support java.util.Calendar? Will solve this in a day or so.

gr. Martin

On 03/30/2012 11:39 AM, Ludwig Moser wrote:
> i'm sorry but i do not understand how i can integrate this into my QuickStart example.
> my current code (of my application) is using Calendar everywhere instead of Date (although it could be converted)


--

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@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Teneo][Hibernate] ClassCastException: [message #832597 is a reply to message #832590] Fri, 30 March 2012 10:29 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
i've created a Bug 375705 i hope thats what you wanted me to do

thanks a lot!
Re: [Teneo][Hibernate] ClassCastException: [message #833692 is a reply to message #832597] Sat, 31 March 2012 22:22 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
thanks for fixing it, martin.
i'll look into Texo now too

[Updated on: Sat, 31 March 2012 22:24]

Report message to a moderator

Re: [Teneo][Hibernate] ClassCastException: [message #834113 is a reply to message #833692] Sun, 01 April 2012 12:22 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Ludwig,
I don't think this error will occur in Texo, let me know if it does.

gr. Martin

On 04/01/2012 12:23 AM, Ludwig Moser wrote:
> thanks for fixing it, martin.
> i'll look into Texo now too (did you fix it there too?)


--

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@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Previous Topic:Refactoring the generated editor
Next Topic:EMF Commands vs GEF Commands
Goto Forum:
  


Current Time: Wed Apr 24 23:13:58 GMT 2024

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

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

Back to the top