Bug 175909 - Date & DateTime XSD mappings are to a VARCHAR and not date or timestamp
Summary: Date & DateTime XSD mappings are to a VARCHAR and not date or timestamp
Status: VERIFIED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: Teneo (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Martin Taal CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2007-02-28 16:14 EST by Brian Vetter CLA
Modified: 2008-05-27 19:19 EDT (History)
0 users

See Also:


Attachments
Patch to the AbstractMapper class (1.18 KB, patch)
2007-02-28 16:16 EST, Brian Vetter CLA
no flags Details | Diff
Patch to the ECoreDataTypes class (2.82 KB, patch)
2007-02-28 16:16 EST, Brian Vetter CLA
no flags Details | Diff
Additional hibernate mapping classes for data and datetime (6.11 KB, patch)
2007-02-28 16:18 EST, Brian Vetter CLA
no flags Details | Diff
A simple XSD that illustrates the problem (473 bytes, text/xml)
2007-02-28 16:20 EST, Brian Vetter CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Vetter CLA 2007-02-28 16:14:25 EST
My elements of type date and datetime are currently mapping to varchar(255) instead of date or datetime in the database. The following XSD element

    <element name="lastReboot" type="dateTime"></element>


maps to the following hbm:

<property name="lastReboot" lazy="false" insert="true" update="true" not-null="false" unique="false">
    <column not-null="false" unique="false" name="`lastreboot`"/>
    <type name="org.eclipse.emf.teneo.hibernate.mapping.DefaultToStringUserType">
        <param name="edatatype">Date</param>
        <param name="epackage">http://www.eclipse.org/emf/2003/XMLType</param>
    </type>
</property>

The ecore mapping looks like:
   <eStructuralFeatures xsi:type="ecore:EAttribute" name="lastReboot" unique="false"
       eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//DateTime">
     <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
       <details key="kind" value="element"/>
       <details key="name" value="lastReboot"/>
       <details key="namespace" value="##targetNamespace"/>
     </eAnnotations>
   </eStructuralFeatures>

Although it looks like the DateTime type is preserved in the mapping, I noticed that the ecore-Java instanceClass for the eDataType is of type "Object". Teneo always maps this to a String.

Underneath, EMF maintains the date through a class called org.eclipse.xsd.impl.type.XSDDateTimeType whose value is an instance of an internal XMLCalendar class. 

I've created a patch to Teneo's hibernate mapping to fix this. I have not done anything with the JPOX/JDO implementation but I suspect it could have similar issues.
Comment 1 Brian Vetter CLA 2007-02-28 16:16:04 EST
Created attachment 60018 [details]
Patch to the AbstractMapper class
Comment 2 Brian Vetter CLA 2007-02-28 16:16:44 EST
Created attachment 60019 [details]
Patch to the ECoreDataTypes class
Comment 3 Brian Vetter CLA 2007-02-28 16:18:36 EST
Created attachment 60020 [details]
Additional hibernate mapping classes for data and datetime

these are new java classes that must go into the org.eclipse.emf.teneo.hibernate.mapping package.
Comment 4 Brian Vetter CLA 2007-02-28 16:20:31 EST
Created attachment 60022 [details]
A simple XSD that illustrates the problem

When Teneo maps this XSD to the database, it results in a VARCHAR(255) in the database. With the patches installed, they end up being date and datetime.
Comment 5 Brian Vetter CLA 2007-02-28 16:22:58 EST
I've included patch files that were generated from the R0_7_maintenance branch tag.
Comment 6 Martin Taal CLA 2007-03-04 16:21:39 EST
Added this in cvs (only for head, the 0.8.0 release). I have made minor changes here and there.

This is only available in the 0.8.0 release. Let me know if this is really a big issue. Then I can add it to the 0.7.5 release.

gr. Martin
Comment 7 Brian Vetter CLA 2007-03-05 00:15:37 EST
Thanks for incorporating it. Unfortunately, I have to work off the Teneo maintenance branch (is the tag 0.7.5 or is it R0_7_maintenance?) since I can't make the jump to the next version (Europa) of Eclipse that is demanded by EMF 2.3 until later this year.
Comment 8 Martin Taal CLA 2007-03-05 01:15:55 EST
Okay, I'll also add it to 0.7.5.

gr. Martin
Comment 9 Martin Taal CLA 2007-03-05 13:17:23 EST
Hi Brian,
I have also applied the changes to the maintenance branch.

gr. Martin
Comment 10 Martin Taal CLA 2007-03-05 15:38:36 EST
Has been committed to cvs for the maintenance branch. Will be in the next release.

gr. Martin
Comment 11 Brian Vetter CLA 2007-03-05 17:00:15 EST
I updated from the maintenance branch and it seems to be working well. Thanks.
Comment 12 Martin Taal CLA 2007-03-09 17:41:12 EST
Has been solved in builds M200703091332 and I200703081604.
Comment 13 Martin Taal CLA 2007-03-09 17:41:52 EST
Thanks for the contribution Brian!

gr. Martin
Comment 14 Nick Boldt CLA 2008-01-28 16:56:53 EST
Move to verified as per bug 206558.