Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo] Date and DateTime mapping?
[Teneo] Date and DateTime mapping? [message #72637] Thu, 22 February 2007 22:18 Go to next message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
My date and datetime types are currently mapping to varchar(255) instead of date. 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.DefaultToStringUserT ype ">
<param name="edatatype">Date</param>
<param name="epackage">http://www.eclipse.org/emf/2003/XMLType</param>
</type>
</property>

What is the magic incantation to get this to map to a DateTime. I get similar results when I use the date type.

I'm not sure if this is an XSD->ecore mapping or a Teneo issue.

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 mapping is to an Object and not a Date-like type.

Is Date/DateTime not being mapped to DB date/datetime in Teneo or is there potentially something wrong in my configuration?

Brian
Re: [Teneo] Date and DateTime mapping? [message #72651 is a reply to message #72637] Thu, 22 February 2007 23:49 Go to previous messageGo to next message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
After poking around in the source, I believe I found the problem in the method isEDate() in org.eclipse.emf.teneo.util.EcoreDataTypes.java

Apparently, the EDataType instance class for date types is of type Object, not one of the java date classes expected in this function. I made the following change to the method and was able to get the datetime mappings I was hoping for, although I didn't try timestamps or any of the other types. I don't know if there are other places where a similar change should be made.

replace this:
public boolean isEDate(EDataType eDataType) {
Class ic = eDataType.getInstanceClass();
return java.util.Date.class == ic || java.util.Calendar.class == ic || java.sql.Date.class == ic;
}

with this:
public boolean isEDate(EDataType eDataType) {
String nm = eDataType.getName();
return nm.equals("DateTime") || nm.equals("Date") || nm.equals("Time");
}

When making this change, the hbType() method will now return a java.util.Date classname instead of null.

This results in the correct mapping, but it isn't quite correct. The problem is that when you populate a dateTime typed element from an XML file, the format of the data doesn't match what XML Schema expects. I tried having AbstractMapper.hbType() return "org.eclipse.xsd.impl.type.XSDDateTimeType" presuming that it could do the proper mapping, but the hibernate mapping code doesn't know how to map one of those to a date and tosses an exception.

It would appear that what is needed is some kind of user defined type in the hibernate mapping layer (extending org.hibernate.UserType) but I'm a bit out over my skis right now. Any suggestions on how to get this to work properly?

Brian

Brian Vetter wrote:
> My date and datetime types are currently mapping to varchar(255) instead
> of date. 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.DefaultToStringUserT ype ">
> <param name="edatatype">Date</param>
> <param
> name="epackage">http://www.eclipse.org/emf/2003/XMLType</param>
> </type>
> </property>
>
> What is the magic incantation to get this to map to a DateTime. I get
> similar results when I use the date type.
>
> I'm not sure if this is an XSD->ecore mapping or a Teneo issue.
>
> 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 mapping is to an Object and not a Date-like
> type.
>
> Is Date/DateTime not being mapped to DB date/datetime in Teneo or is
> there potentially something wrong in my configuration?
> Brian
Re: [Teneo] Date and DateTime mapping? [message #72664 is a reply to message #72651] Fri, 23 February 2007 07:07 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Brian,
What class was ic in your case?

gr. Martin

Brian Vetter wrote:
> After poking around in the source, I believe I found the problem in the
> method isEDate() in org.eclipse.emf.teneo.util.EcoreDataTypes.java
>
> Apparently, the EDataType instance class for date types is of type
> Object, not one of the java date classes expected in this function. I
> made the following change to the method and was able to get the datetime
> mappings I was hoping for, although I didn't try timestamps or any of
> the other types. I don't know if there are other places where a similar
> change should be made.
>
> replace this:
> public boolean isEDate(EDataType eDataType) {
> Class ic = eDataType.getInstanceClass();
> return java.util.Date.class == ic || java.util.Calendar.class == ic
> || java.sql.Date.class == ic;
> }
>
> with this:
> public boolean isEDate(EDataType eDataType) {
> String nm = eDataType.getName();
> return nm.equals("DateTime") || nm.equals("Date") || nm.equals("Time");
> }
>
> When making this change, the hbType() method will now return a
> java.util.Date classname instead of null.
>
> This results in the correct mapping, but it isn't quite correct. The
> problem is that when you populate a dateTime typed element from an XML
> file, the format of the data doesn't match what XML Schema expects. I
> tried having AbstractMapper.hbType() return
> "org.eclipse.xsd.impl.type.XSDDateTimeType" presuming that it could do
> the proper mapping, but the hibernate mapping code doesn't know how to
> map one of those to a date and tosses an exception.
>
> It would appear that what is needed is some kind of user defined type in
> the hibernate mapping layer (extending org.hibernate.UserType) but I'm a
> bit out over my skis right now. Any suggestions on how to get this to
> work properly?
>
> Brian
>
> Brian Vetter wrote:
>> My date and datetime types are currently mapping to varchar(255)
>> instead of date. 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.DefaultToStringUserT ype ">
>> <param name="edatatype">Date</param>
>> <param
>> name="epackage">http://www.eclipse.org/emf/2003/XMLType</param>
>> </type>
>> </property>
>>
>> What is the magic incantation to get this to map to a DateTime. I get
>> similar results when I use the date type.
>>
>> I'm not sure if this is an XSD->ecore mapping or a Teneo issue.
>>
>> 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 mapping is to an Object and not a
>> Date-like type.
>>
>> Is Date/DateTime not being mapped to DB date/datetime in Teneo or is
>> there potentially something wrong in my configuration? Brian


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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] Date and DateTime mapping? [message #72679 is a reply to message #72664] Fri, 23 February 2007 08:59 Go to previous messageGo to next message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
ic for the datetime elements were coming back as type "java.lang.Object". However, somewhere under the covers in EMF, the actual type is org.eclipse.emf.ecore.xml.type.internal.XMLCalendar (I was able to get a cast exception when I tried to map it as a java.util.Date type).

Just for grins, I implemented a hibernate usertype that maps the org.eclipse.emf.ecore.xml.type.internal.XMLCalendar class. I then modified hbtype() in AbstractMapper to return my user type class instead of "java.util.Date".

So far, it is working (the mapping is correct) but with one caveat - It is tracking the dates properly, but for some reason, I'm losing the time precision (everything is at 12:00).

Brian

Martin Taal wrote:
> Brian,
> What class was ic in your case?
>
> gr. Martin
>
> Brian Vetter wrote:
>> After poking around in the source, I believe I found the problem in
>> the method isEDate() in org.eclipse.emf.teneo.util.EcoreDataTypes.java
>>
>> Apparently, the EDataType instance class for date types is of type
>> Object, not one of the java date classes expected in this function. I
>> made the following change to the method and was able to get the
>> datetime mappings I was hoping for, although I didn't try timestamps
>> or any of the other types. I don't know if there are other places
>> where a similar change should be made.
>>
>> replace this:
>> public boolean isEDate(EDataType eDataType) {
>> Class ic = eDataType.getInstanceClass();
>> return java.util.Date.class == ic || java.util.Calendar.class ==
>> ic || java.sql.Date.class == ic;
>> }
>>
>> with this:
>> public boolean isEDate(EDataType eDataType) {
>> String nm = eDataType.getName();
>> return nm.equals("DateTime") || nm.equals("Date") ||
>> nm.equals("Time");
>> }
>>
>> When making this change, the hbType() method will now return a
>> java.util.Date classname instead of null.
>>
>> This results in the correct mapping, but it isn't quite correct. The
>> problem is that when you populate a dateTime typed element from an XML
>> file, the format of the data doesn't match what XML Schema expects. I
>> tried having AbstractMapper.hbType() return
>> "org.eclipse.xsd.impl.type.XSDDateTimeType" presuming that it could do
>> the proper mapping, but the hibernate mapping code doesn't know how to
>> map one of those to a date and tosses an exception.
>>
>> It would appear that what is needed is some kind of user defined type
>> in the hibernate mapping layer (extending org.hibernate.UserType) but
>> I'm a bit out over my skis right now. Any suggestions on how to get
>> this to work properly?
>>
>> Brian
>>
>> Brian Vetter wrote:
>>> My date and datetime types are currently mapping to varchar(255)
>>> instead of date. 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.DefaultToStringUserT ype ">
>>> <param name="edatatype">Date</param>
>>> <param
>>> name="epackage">http://www.eclipse.org/emf/2003/XMLType</param>
>>> </type>
>>> </property>
>>>
>>> What is the magic incantation to get this to map to a DateTime. I get
>>> similar results when I use the date type.
>>>
>>> I'm not sure if this is an XSD->ecore mapping or a Teneo issue.
>>>
>>> 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 mapping is to an Object and not a
>>> Date-like type.
>>>
>>> Is Date/DateTime not being mapped to DB date/datetime in Teneo or is
>>> there potentially something wrong in my configuration? Brian
>
>
Re: [Teneo] Date and DateTime mapping? [message #72692 is a reply to message #72664] Fri, 23 February 2007 09:51 Go to previous messageGo to next message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
BTW, I found the problem in my user type where it was losing the hours/minutes.

I'd be more than happy to share it with you if you believe that adding a special type for datetime is the way to solve the problem.

Brian

Martin Taal wrote:
> Brian,
> What class was ic in your case?
>
> gr. Martin
>
> Brian Vetter wrote:
>> After poking around in the source, I believe I found the problem in
>> the method isEDate() in org.eclipse.emf.teneo.util.EcoreDataTypes.java
>>
>> Apparently, the EDataType instance class for date types is of type
>> Object, not one of the java date classes expected in this function. I
>> made the following change to the method and was able to get the
>> datetime mappings I was hoping for, although I didn't try timestamps
>> or any of the other types. I don't know if there are other places
>> where a similar change should be made.
>>
>> replace this:
>> public boolean isEDate(EDataType eDataType) {
>> Class ic = eDataType.getInstanceClass();
>> return java.util.Date.class == ic || java.util.Calendar.class ==
>> ic || java.sql.Date.class == ic;
>> }
>>
>> with this:
>> public boolean isEDate(EDataType eDataType) {
>> String nm = eDataType.getName();
>> return nm.equals("DateTime") || nm.equals("Date") ||
>> nm.equals("Time");
>> }
>>
>> When making this change, the hbType() method will now return a
>> java.util.Date classname instead of null.
>>
>> This results in the correct mapping, but it isn't quite correct. The
>> problem is that when you populate a dateTime typed element from an XML
>> file, the format of the data doesn't match what XML Schema expects. I
>> tried having AbstractMapper.hbType() return
>> "org.eclipse.xsd.impl.type.XSDDateTimeType" presuming that it could do
>> the proper mapping, but the hibernate mapping code doesn't know how to
>> map one of those to a date and tosses an exception.
>>
>> It would appear that what is needed is some kind of user defined type
>> in the hibernate mapping layer (extending org.hibernate.UserType) but
>> I'm a bit out over my skis right now. Any suggestions on how to get
>> this to work properly?
>>
>> Brian
>>
>> Brian Vetter wrote:
>>> My date and datetime types are currently mapping to varchar(255)
>>> instead of date. 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.DefaultToStringUserT ype ">
>>> <param name="edatatype">Date</param>
>>> <param
>>> name="epackage">http://www.eclipse.org/emf/2003/XMLType</param>
>>> </type>
>>> </property>
>>>
>>> What is the magic incantation to get this to map to a DateTime. I get
>>> similar results when I use the date type.
>>>
>>> I'm not sure if this is an XSD->ecore mapping or a Teneo issue.
>>>
>>> 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 mapping is to an Object and not a
>>> Date-like type.
>>>
>>> Is Date/DateTime not being mapped to DB date/datetime in Teneo or is
>>> there potentially something wrong in my configuration? Brian
>
>
Re: [Teneo] Date and DateTime mapping? [message #72704 is a reply to message #72692] Fri, 23 February 2007 11:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------090102080205020907010008
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Brian,

I'm still looking at using
https://bugs.eclipse.org/bugs/show_bug.cgi?id=172063 to switch to using
the XMLGregorianCalendar and Duration now that we can depend on JDK 5.0
classes. It looks like we can't stop using our own internal QName class
because our QName class needs to be mutable and the JDK's implementation
is not. I'm concerned that this switch will lead to binary
incompatibility problems when methods like this in XMLTypeFactory

Object createDateTime(String literal);

change to

XMLGregorianCalendar createDateTime(String literal);

and of course there will be similar changes for features of these
EDataTypes in existing generated client APIs.

I'm not sure what's best... Comments are welcome...


Brian Vetter wrote:
> BTW, I found the problem in my user type where it was losing the
> hours/minutes.
>
> I'd be more than happy to share it with you if you believe that adding
> a special type for datetime is the way to solve the problem.
>
> Brian
>
> Martin Taal wrote:
>> Brian,
>> What class was ic in your case?
>>
>> gr. Martin
>>
>> Brian Vetter wrote:
>>> After poking around in the source, I believe I found the problem in
>>> the method isEDate() in org.eclipse.emf.teneo.util.EcoreDataTypes.java
>>>
>>> Apparently, the EDataType instance class for date types is of type
>>> Object, not one of the java date classes expected in this function.
>>> I made the following change to the method and was able to get the
>>> datetime mappings I was hoping for, although I didn't try timestamps
>>> or any of the other types. I don't know if there are other places
>>> where a similar change should be made.
>>>
>>> replace this:
>>> public boolean isEDate(EDataType eDataType) {
>>> Class ic = eDataType.getInstanceClass();
>>> return java.util.Date.class == ic || java.util.Calendar.class ==
>>> ic || java.sql.Date.class == ic;
>>> }
>>>
>>> with this:
>>> public boolean isEDate(EDataType eDataType) {
>>> String nm = eDataType.getName();
>>> return nm.equals("DateTime") || nm.equals("Date") ||
>>> nm.equals("Time");
>>> }
>>>
>>> When making this change, the hbType() method will now return a
>>> java.util.Date classname instead of null.
>>>
>>> This results in the correct mapping, but it isn't quite correct. The
>>> problem is that when you populate a dateTime typed element from an
>>> XML file, the format of the data doesn't match what XML Schema
>>> expects. I tried having AbstractMapper.hbType() return
>>> "org.eclipse.xsd.impl.type.XSDDateTimeType" presuming that it could
>>> do the proper mapping, but the hibernate mapping code doesn't know
>>> how to map one of those to a date and tosses an exception.
>>>
>>> It would appear that what is needed is some kind of user defined
>>> type in the hibernate mapping layer (extending
>>> org.hibernate.UserType) but I'm a bit out over my skis right now.
>>> Any suggestions on how to get this to work properly?
>>>
>>> Brian
>>>
>>> Brian Vetter wrote:
>>>> My date and datetime types are currently mapping to varchar(255)
>>>> instead of date. 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.DefaultToStringUserT ype ">
>>>>
>>>> <param name="edatatype">Date</param>
>>>> <param
>>>> name="epackage">http://www.eclipse.org/emf/2003/XMLType</param>
>>>> </type>
>>>> </property>
>>>>
>>>> What is the magic incantation to get this to map to a DateTime. I
>>>> get similar results when I use the date type.
>>>>
>>>> I'm not sure if this is an XSD->ecore mapping or a Teneo issue.
>>>>
>>>> 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 mapping is to an Object and
>>>> not a Date-like type.
>>>>
>>>> Is Date/DateTime not being mapped to DB date/datetime in Teneo or
>>>> is there potentially something wrong in my configuration? Brian
>>
>>


--------------090102080205020907010008
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Brian,<br>
<br>
I'm still looking at using <a
href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=172063">https://bugs.eclipse.org/bugs/show_bug.cgi?id=172063</a>
to switch to using the XMLGregorianCalendar and Duration now that we
can depend on JDK 5.0 classes.&nbsp; It looks like we can't stop using our
own internal QName class because our QName class needs to be mutable
and the JDK's implementation is not.&nbsp; I'm concerned that this switch
will lead to binary incompatibility problems when methods like this in
XMLTypeFactory<br>
<blockquote>&nbsp; Object createDateTime(String literal);<br>
</blockquote>
change to<br>
<blockquote>&nbsp; XMLGregorianCalendar createDateTime(String literal);<br>
</blockquote>
and of course there will be similar changes for features of these
EDataTypes in existing generated client APIs.<br>
<br>
I'm not sure what's best...&nbsp; Comments are welcome...<br>
<br>
<br>
Brian Vetter wrote:
<blockquote cite="midermdf2$1v1$1@utils.eclipse.org" type="cite">BTW, I
found the problem in my user type where it was losing the
hours/minutes.
<br>
<br>
I'd be more than happy to share it with you if you believe that adding
a special type for datetime is the way to solve the problem.
<br>
<br>
Brian
<br>
<br>
Martin Taal wrote:
<br>
<blockquote type="cite">Brian,
<br>
What class was ic in your case?
<br>
<br>
gr. Martin
<br>
<br>
Brian Vetter wrote:
<br>
<blockquote type="cite">After poking around in the source, I
believe I found the problem in the method isEDate() in
org.eclipse.emf.teneo.util.EcoreDataTypes.java
<br>
<br>
Apparently, the EDataType instance class for date types is of type
Object, not one of the java date classes expected in this function. I
made the following change to the method and was able to get the
datetime mappings I was hoping for, although I didn't try timestamps or
any of the other types. I don't know if there are other places where a
similar change should be made.
<br>
<br>
replace this:
<br>
public boolean isEDate(EDataType eDataType) {
<br>
&nbsp;&nbsp;&nbsp; Class ic = eDataType.getInstanceClass();
<br>
&nbsp;&nbsp;&nbsp; return java.util.Date.class == ic || java.util.Calendar.class == ic
|| java.sql.Date.class == ic;
<br>
}
<br>
<br>
with this:
<br>
public boolean isEDate(EDataType eDataType) {
<br>
&nbsp;&nbsp;&nbsp; String nm = eDataType.getName();
<br>
&nbsp;&nbsp;&nbsp; return nm.equals("DateTime") || nm.equals("Date") ||
nm.equals("Time");
<br>
}
<br>
<br>
When making this change, the hbType() method will now return a
java.util.Date classname instead of null.
<br>
<br>
This results in the correct mapping, but it isn't quite correct. The
problem is that when you populate a dateTime typed element from an XML
file, the format of the data doesn't match what XML Schema expects. I
tried having AbstractMapper.hbType() return
"org.eclipse.xsd.impl.type.XSDDateTimeType" presuming that it could do
the proper mapping, but the hibernate mapping code doesn't know how to
map one of those to a date and tosses an exception.
<br>
<br>
It would appear that what is needed is some kind of user defined type
in the hibernate mapping layer (extending org.hibernate.UserType) but
I'm a bit out over my skis right now. Any suggestions on how to get
this to work properly?
<br>
<br>
Brian
<br>
<br>
Brian Vetter wrote:
<br>
<blockquote type="cite">My date and datetime types are currently
mapping to varchar(255) instead of date. The following XSD element
<br>
<br>
&nbsp;&nbsp;&nbsp; &lt;element name="lastReboot" type="dateTime"&gt;&lt;/element&gt;
<br>
<br>
<br>
maps to the following hbm:
<br>
<br>
&lt;property name="lastReboot" lazy="false" insert="true" update="true"
not-null="false" unique="false"&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;column not-null="false" unique="false" name="`lastreboot`"/&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;type
name=" org.eclipse.emf.teneo.hibernate.mapping.DefaultToStringUserT ype "&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;param name="edatatype"&gt;Date&lt;/param&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;param
name="epackage"&gt;<a class="moz-txt-link-freetext" href="http://www.eclipse.org/emf/2003/XMLType">http://www.eclipse.org/emf/2003/XMLType</a>&lt;/param&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;/type&gt;
<br>
&lt;/property&gt;
<br>
<br>
What is the magic incantation to get this to map to a DateTime. I get
similar results when I use the date type.
<br>
<br>
I'm not sure if this is an XSD-&gt;ecore mapping or a Teneo issue.
<br>
<br>
The ecore mapping looks like:
<br>
&nbsp;&nbsp; &lt;eStructuralFeatures xsi:type="ecore:EAttribute"
name="lastReboot" unique="false"
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; eType="ecore:EDataType
<a class="moz-txt-link-freetext" href="http://www.eclipse.org/emf/2003/XMLType#//DateTime">http://www.eclipse.org/emf/2003/XMLType#//DateTime</a>"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;details key="kind" value="element"/&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;details key="name" value="lastReboot"/&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;details key="namespace" value="##targetNamespace"/&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;/eAnnotations&gt;
<br>
&nbsp;&nbsp; &lt;/eStructuralFeatures&gt;
<br>
<br>
Although it looks like the DateTime type is preserved in the mapping, I
noticed that the ecore-Java mapping is to an Object and not a Date-like
type.
<br>
<br>
Is Date/DateTime not being mapped to DB date/datetime in Teneo or is
there potentially something wrong in my configuration? Brian
<br>
</blockquote>
</blockquote>
<br>
<br>
</blockquote>
</blockquote>
<br>
</body>
</html>

--------------090102080205020907010008--
Re: [Teneo] Date and DateTime mapping? [message #72715 is a reply to message #72704] Fri, 23 February 2007 17:24 Go to previous messageGo to next message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
I think if XMLGregorianCalendar had extended Calendar (or GregorianCalendar), it would be more alluring to use directly. The ability for an app to treat it as either would have been useful. Since XMLGregorianCalendar is unrelated, I'm not sure you get any benefit to using it directly.

The safer approach would be to refactor emf's XMLCalendar class to use XMLGregorianCalendar for all of its parsing/serialization features instead of implementing its own.

Brian

Ed Merks wrote:
> Brian,
>
> I'm still looking at using
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=172063 to switch to using
> the XMLGregorianCalendar and Duration now that we can depend on JDK 5.0
> classes. It looks like we can't stop using our own internal QName class
> because our QName class needs to be mutable and the JDK's implementation
> is not. I'm concerned that this switch will lead to binary
> incompatibility problems when methods like this in XMLTypeFactory
>
> Object createDateTime(String literal);
>
> change to
>
> XMLGregorianCalendar createDateTime(String literal);
>
> and of course there will be similar changes for features of these
> EDataTypes in existing generated client APIs.
>
> I'm not sure what's best... Comments are welcome...
>
>
> Brian Vetter wrote:
>> BTW, I found the problem in my user type where it was losing the
>> hours/minutes.
>>
>> I'd be more than happy to share it with you if you believe that adding
>> a special type for datetime is the way to solve the problem.
>>
>> Brian
>>
>>
Re: [Teneo] Date and DateTime mapping? [message #72822 is a reply to message #72692] Sun, 25 February 2007 15:32 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Brian,
Thanks, can you enter a bugzilla for this and attach your patch to it? If possible can you also
attach a small xsd model which illustrates the problem.

gr. Martin

Brian Vetter wrote:
> BTW, I found the problem in my user type where it was losing the
> hours/minutes.
>
> I'd be more than happy to share it with you if you believe that adding a
> special type for datetime is the way to solve the problem.
>
> Brian
>
> Martin Taal wrote:
>> Brian,
>> What class was ic in your case?
>>
>> gr. Martin
>>
>> Brian Vetter wrote:
>>> After poking around in the source, I believe I found the problem in
>>> the method isEDate() in org.eclipse.emf.teneo.util.EcoreDataTypes.java
>>>
>>> Apparently, the EDataType instance class for date types is of type
>>> Object, not one of the java date classes expected in this function. I
>>> made the following change to the method and was able to get the
>>> datetime mappings I was hoping for, although I didn't try timestamps
>>> or any of the other types. I don't know if there are other places
>>> where a similar change should be made.
>>>
>>> replace this:
>>> public boolean isEDate(EDataType eDataType) {
>>> Class ic = eDataType.getInstanceClass();
>>> return java.util.Date.class == ic || java.util.Calendar.class ==
>>> ic || java.sql.Date.class == ic;
>>> }
>>>
>>> with this:
>>> public boolean isEDate(EDataType eDataType) {
>>> String nm = eDataType.getName();
>>> return nm.equals("DateTime") || nm.equals("Date") ||
>>> nm.equals("Time");
>>> }
>>>
>>> When making this change, the hbType() method will now return a
>>> java.util.Date classname instead of null.
>>>
>>> This results in the correct mapping, but it isn't quite correct. The
>>> problem is that when you populate a dateTime typed element from an
>>> XML file, the format of the data doesn't match what XML Schema
>>> expects. I tried having AbstractMapper.hbType() return
>>> "org.eclipse.xsd.impl.type.XSDDateTimeType" presuming that it could
>>> do the proper mapping, but the hibernate mapping code doesn't know
>>> how to map one of those to a date and tosses an exception.
>>>
>>> It would appear that what is needed is some kind of user defined type
>>> in the hibernate mapping layer (extending org.hibernate.UserType) but
>>> I'm a bit out over my skis right now. Any suggestions on how to get
>>> this to work properly?
>>>
>>> Brian
>>>
>>> Brian Vetter wrote:
>>>> My date and datetime types are currently mapping to varchar(255)
>>>> instead of date. 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.DefaultToStringUserT ype ">
>>>> <param name="edatatype">Date</param>
>>>> <param
>>>> name="epackage">http://www.eclipse.org/emf/2003/XMLType</param>
>>>> </type>
>>>> </property>
>>>>
>>>> What is the magic incantation to get this to map to a DateTime. I
>>>> get similar results when I use the date type.
>>>>
>>>> I'm not sure if this is an XSD->ecore mapping or a Teneo issue.
>>>>
>>>> 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 mapping is to an Object and
>>>> not a Date-like type.
>>>>
>>>> Is Date/DateTime not being mapped to DB date/datetime in Teneo or is
>>>> there potentially something wrong in my configuration? Brian
>>
>>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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] Date and DateTime mapping? [message #73332 is a reply to message #72822] Wed, 28 February 2007 21:23 Go to previous message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
I've created bugzilla 175909 and attached 4 files (3 patch files) and one xsd example to it.

Brian

Martin Taal wrote:
> Hi Brian,
> Thanks, can you enter a bugzilla for this and attach your patch to it?
> If possible can you also attach a small xsd model which illustrates the
> problem.
>
> gr. Martin
>
> Brian Vetter wrote:
>> BTW, I found the problem in my user type where it was losing the
>> hours/minutes.
>>
>> I'd be more than happy to share it with you if you believe that adding
>> a special type for datetime is the way to solve the problem.
>>
>> Brian
>>
Re: [Teneo] Date and DateTime mapping? [message #602900 is a reply to message #72637] Thu, 22 February 2007 23:49 Go to previous message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
After poking around in the source, I believe I found the problem in the method isEDate() in org.eclipse.emf.teneo.util.EcoreDataTypes.java

Apparently, the EDataType instance class for date types is of type Object, not one of the java date classes expected in this function. I made the following change to the method and was able to get the datetime mappings I was hoping for, although I didn't try timestamps or any of the other types. I don't know if there are other places where a similar change should be made.

replace this:
public boolean isEDate(EDataType eDataType) {
Class ic = eDataType.getInstanceClass();
return java.util.Date.class == ic || java.util.Calendar.class == ic || java.sql.Date.class == ic;
}

with this:
public boolean isEDate(EDataType eDataType) {
String nm = eDataType.getName();
return nm.equals("DateTime") || nm.equals("Date") || nm.equals("Time");
}

When making this change, the hbType() method will now return a java.util.Date classname instead of null.

This results in the correct mapping, but it isn't quite correct. The problem is that when you populate a dateTime typed element from an XML file, the format of the data doesn't match what XML Schema expects. I tried having AbstractMapper.hbType() return "org.eclipse.xsd.impl.type.XSDDateTimeType" presuming that it could do the proper mapping, but the hibernate mapping code doesn't know how to map one of those to a date and tosses an exception.

It would appear that what is needed is some kind of user defined type in the hibernate mapping layer (extending org.hibernate.UserType) but I'm a bit out over my skis right now. Any suggestions on how to get this to work properly?

Brian

Brian Vetter wrote:
> My date and datetime types are currently mapping to varchar(255) instead
> of date. 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.DefaultToStringUserT ype ">
> <param name="edatatype">Date</param>
> <param
> name="epackage">http://www.eclipse.org/emf/2003/XMLType</param>
> </type>
> </property>
>
> What is the magic incantation to get this to map to a DateTime. I get
> similar results when I use the date type.
>
> I'm not sure if this is an XSD->ecore mapping or a Teneo issue.
>
> 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 mapping is to an Object and not a Date-like
> type.
>
> Is Date/DateTime not being mapped to DB date/datetime in Teneo or is
> there potentially something wrong in my configuration?
> Brian
Re: [Teneo] Date and DateTime mapping? [message #602903 is a reply to message #72651] Fri, 23 February 2007 07:07 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Brian,
What class was ic in your case?

gr. Martin

Brian Vetter wrote:
> After poking around in the source, I believe I found the problem in the
> method isEDate() in org.eclipse.emf.teneo.util.EcoreDataTypes.java
>
> Apparently, the EDataType instance class for date types is of type
> Object, not one of the java date classes expected in this function. I
> made the following change to the method and was able to get the datetime
> mappings I was hoping for, although I didn't try timestamps or any of
> the other types. I don't know if there are other places where a similar
> change should be made.
>
> replace this:
> public boolean isEDate(EDataType eDataType) {
> Class ic = eDataType.getInstanceClass();
> return java.util.Date.class == ic || java.util.Calendar.class == ic
> || java.sql.Date.class == ic;
> }
>
> with this:
> public boolean isEDate(EDataType eDataType) {
> String nm = eDataType.getName();
> return nm.equals("DateTime") || nm.equals("Date") || nm.equals("Time");
> }
>
> When making this change, the hbType() method will now return a
> java.util.Date classname instead of null.
>
> This results in the correct mapping, but it isn't quite correct. The
> problem is that when you populate a dateTime typed element from an XML
> file, the format of the data doesn't match what XML Schema expects. I
> tried having AbstractMapper.hbType() return
> "org.eclipse.xsd.impl.type.XSDDateTimeType" presuming that it could do
> the proper mapping, but the hibernate mapping code doesn't know how to
> map one of those to a date and tosses an exception.
>
> It would appear that what is needed is some kind of user defined type in
> the hibernate mapping layer (extending org.hibernate.UserType) but I'm a
> bit out over my skis right now. Any suggestions on how to get this to
> work properly?
>
> Brian
>
> Brian Vetter wrote:
>> My date and datetime types are currently mapping to varchar(255)
>> instead of date. 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.DefaultToStringUserT ype ">
>> <param name="edatatype">Date</param>
>> <param
>> name="epackage">http://www.eclipse.org/emf/2003/XMLType</param>
>> </type>
>> </property>
>>
>> What is the magic incantation to get this to map to a DateTime. I get
>> similar results when I use the date type.
>>
>> I'm not sure if this is an XSD->ecore mapping or a Teneo issue.
>>
>> 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 mapping is to an Object and not a
>> Date-like type.
>>
>> Is Date/DateTime not being mapped to DB date/datetime in Teneo or is
>> there potentially something wrong in my configuration? Brian


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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] Date and DateTime mapping? [message #602908 is a reply to message #72664] Fri, 23 February 2007 08:59 Go to previous message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
ic for the datetime elements were coming back as type "java.lang.Object". However, somewhere under the covers in EMF, the actual type is org.eclipse.emf.ecore.xml.type.internal.XMLCalendar (I was able to get a cast exception when I tried to map it as a java.util.Date type).

Just for grins, I implemented a hibernate usertype that maps the org.eclipse.emf.ecore.xml.type.internal.XMLCalendar class. I then modified hbtype() in AbstractMapper to return my user type class instead of "java.util.Date".

So far, it is working (the mapping is correct) but with one caveat - It is tracking the dates properly, but for some reason, I'm losing the time precision (everything is at 12:00).

Brian

Martin Taal wrote:
> Brian,
> What class was ic in your case?
>
> gr. Martin
>
> Brian Vetter wrote:
>> After poking around in the source, I believe I found the problem in
>> the method isEDate() in org.eclipse.emf.teneo.util.EcoreDataTypes.java
>>
>> Apparently, the EDataType instance class for date types is of type
>> Object, not one of the java date classes expected in this function. I
>> made the following change to the method and was able to get the
>> datetime mappings I was hoping for, although I didn't try timestamps
>> or any of the other types. I don't know if there are other places
>> where a similar change should be made.
>>
>> replace this:
>> public boolean isEDate(EDataType eDataType) {
>> Class ic = eDataType.getInstanceClass();
>> return java.util.Date.class == ic || java.util.Calendar.class ==
>> ic || java.sql.Date.class == ic;
>> }
>>
>> with this:
>> public boolean isEDate(EDataType eDataType) {
>> String nm = eDataType.getName();
>> return nm.equals("DateTime") || nm.equals("Date") ||
>> nm.equals("Time");
>> }
>>
>> When making this change, the hbType() method will now return a
>> java.util.Date classname instead of null.
>>
>> This results in the correct mapping, but it isn't quite correct. The
>> problem is that when you populate a dateTime typed element from an XML
>> file, the format of the data doesn't match what XML Schema expects. I
>> tried having AbstractMapper.hbType() return
>> "org.eclipse.xsd.impl.type.XSDDateTimeType" presuming that it could do
>> the proper mapping, but the hibernate mapping code doesn't know how to
>> map one of those to a date and tosses an exception.
>>
>> It would appear that what is needed is some kind of user defined type
>> in the hibernate mapping layer (extending org.hibernate.UserType) but
>> I'm a bit out over my skis right now. Any suggestions on how to get
>> this to work properly?
>>
>> Brian
>>
>> Brian Vetter wrote:
>>> My date and datetime types are currently mapping to varchar(255)
>>> instead of date. 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.DefaultToStringUserT ype ">
>>> <param name="edatatype">Date</param>
>>> <param
>>> name="epackage">http://www.eclipse.org/emf/2003/XMLType</param>
>>> </type>
>>> </property>
>>>
>>> What is the magic incantation to get this to map to a DateTime. I get
>>> similar results when I use the date type.
>>>
>>> I'm not sure if this is an XSD->ecore mapping or a Teneo issue.
>>>
>>> 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 mapping is to an Object and not a
>>> Date-like type.
>>>
>>> Is Date/DateTime not being mapped to DB date/datetime in Teneo or is
>>> there potentially something wrong in my configuration? Brian
>
>
Re: [Teneo] Date and DateTime mapping? [message #602912 is a reply to message #72664] Fri, 23 February 2007 09:51 Go to previous message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
BTW, I found the problem in my user type where it was losing the hours/minutes.

I'd be more than happy to share it with you if you believe that adding a special type for datetime is the way to solve the problem.

Brian

Martin Taal wrote:
> Brian,
> What class was ic in your case?
>
> gr. Martin
>
> Brian Vetter wrote:
>> After poking around in the source, I believe I found the problem in
>> the method isEDate() in org.eclipse.emf.teneo.util.EcoreDataTypes.java
>>
>> Apparently, the EDataType instance class for date types is of type
>> Object, not one of the java date classes expected in this function. I
>> made the following change to the method and was able to get the
>> datetime mappings I was hoping for, although I didn't try timestamps
>> or any of the other types. I don't know if there are other places
>> where a similar change should be made.
>>
>> replace this:
>> public boolean isEDate(EDataType eDataType) {
>> Class ic = eDataType.getInstanceClass();
>> return java.util.Date.class == ic || java.util.Calendar.class ==
>> ic || java.sql.Date.class == ic;
>> }
>>
>> with this:
>> public boolean isEDate(EDataType eDataType) {
>> String nm = eDataType.getName();
>> return nm.equals("DateTime") || nm.equals("Date") ||
>> nm.equals("Time");
>> }
>>
>> When making this change, the hbType() method will now return a
>> java.util.Date classname instead of null.
>>
>> This results in the correct mapping, but it isn't quite correct. The
>> problem is that when you populate a dateTime typed element from an XML
>> file, the format of the data doesn't match what XML Schema expects. I
>> tried having AbstractMapper.hbType() return
>> "org.eclipse.xsd.impl.type.XSDDateTimeType" presuming that it could do
>> the proper mapping, but the hibernate mapping code doesn't know how to
>> map one of those to a date and tosses an exception.
>>
>> It would appear that what is needed is some kind of user defined type
>> in the hibernate mapping layer (extending org.hibernate.UserType) but
>> I'm a bit out over my skis right now. Any suggestions on how to get
>> this to work properly?
>>
>> Brian
>>
>> Brian Vetter wrote:
>>> My date and datetime types are currently mapping to varchar(255)
>>> instead of date. 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.DefaultToStringUserT ype ">
>>> <param name="edatatype">Date</param>
>>> <param
>>> name="epackage">http://www.eclipse.org/emf/2003/XMLType</param>
>>> </type>
>>> </property>
>>>
>>> What is the magic incantation to get this to map to a DateTime. I get
>>> similar results when I use the date type.
>>>
>>> I'm not sure if this is an XSD->ecore mapping or a Teneo issue.
>>>
>>> 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 mapping is to an Object and not a
>>> Date-like type.
>>>
>>> Is Date/DateTime not being mapped to DB date/datetime in Teneo or is
>>> there potentially something wrong in my configuration? Brian
>
>
Re: [Teneo] Date and DateTime mapping? [message #602917 is a reply to message #72692] Fri, 23 February 2007 11:47 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 31536
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090102080205020907010008
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Brian,

I'm still looking at using
https://bugs.eclipse.org/bugs/show_bug.cgi?id=172063 to switch to using
the XMLGregorianCalendar and Duration now that we can depend on JDK 5.0
classes. It looks like we can't stop using our own internal QName class
because our QName class needs to be mutable and the JDK's implementation
is not. I'm concerned that this switch will lead to binary
incompatibility problems when methods like this in XMLTypeFactory

Object createDateTime(String literal);

change to

XMLGregorianCalendar createDateTime(String literal);

and of course there will be similar changes for features of these
EDataTypes in existing generated client APIs.

I'm not sure what's best... Comments are welcome...


Brian Vetter wrote:
> BTW, I found the problem in my user type where it was losing the
> hours/minutes.
>
> I'd be more than happy to share it with you if you believe that adding
> a special type for datetime is the way to solve the problem.
>
> Brian
>
> Martin Taal wrote:
>> Brian,
>> What class was ic in your case?
>>
>> gr. Martin
>>
>> Brian Vetter wrote:
>>> After poking around in the source, I believe I found the problem in
>>> the method isEDate() in org.eclipse.emf.teneo.util.EcoreDataTypes.java
>>>
>>> Apparently, the EDataType instance class for date types is of type
>>> Object, not one of the java date classes expected in this function.
>>> I made the following change to the method and was able to get the
>>> datetime mappings I was hoping for, although I didn't try timestamps
>>> or any of the other types. I don't know if there are other places
>>> where a similar change should be made.
>>>
>>> replace this:
>>> public boolean isEDate(EDataType eDataType) {
>>> Class ic = eDataType.getInstanceClass();
>>> return java.util.Date.class == ic || java.util.Calendar.class ==
>>> ic || java.sql.Date.class == ic;
>>> }
>>>
>>> with this:
>>> public boolean isEDate(EDataType eDataType) {
>>> String nm = eDataType.getName();
>>> return nm.equals("DateTime") || nm.equals("Date") ||
>>> nm.equals("Time");
>>> }
>>>
>>> When making this change, the hbType() method will now return a
>>> java.util.Date classname instead of null.
>>>
>>> This results in the correct mapping, but it isn't quite correct. The
>>> problem is that when you populate a dateTime typed element from an
>>> XML file, the format of the data doesn't match what XML Schema
>>> expects. I tried having AbstractMapper.hbType() return
>>> "org.eclipse.xsd.impl.type.XSDDateTimeType" presuming that it could
>>> do the proper mapping, but the hibernate mapping code doesn't know
>>> how to map one of those to a date and tosses an exception.
>>>
>>> It would appear that what is needed is some kind of user defined
>>> type in the hibernate mapping layer (extending
>>> org.hibernate.UserType) but I'm a bit out over my skis right now.
>>> Any suggestions on how to get this to work properly?
>>>
>>> Brian
>>>
>>> Brian Vetter wrote:
>>>> My date and datetime types are currently mapping to varchar(255)
>>>> instead of date. 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.DefaultToStringUserT ype ">
>>>>
>>>> <param name="edatatype">Date</param>
>>>> <param
>>>> name="epackage">http://www.eclipse.org/emf/2003/XMLType</param>
>>>> </type>
>>>> </property>
>>>>
>>>> What is the magic incantation to get this to map to a DateTime. I
>>>> get similar results when I use the date type.
>>>>
>>>> I'm not sure if this is an XSD->ecore mapping or a Teneo issue.
>>>>
>>>> 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 mapping is to an Object and
>>>> not a Date-like type.
>>>>
>>>> Is Date/DateTime not being mapped to DB date/datetime in Teneo or
>>>> is there potentially something wrong in my configuration? Brian
>>
>>


--------------090102080205020907010008
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Brian,<br>
<br>
I'm still looking at using <a
href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=172063">https://bugs.eclipse.org/bugs/show_bug.cgi?id=172063</a>
to switch to using the XMLGregorianCalendar and Duration now that we
can depend on JDK 5.0 classes.&nbsp; It looks like we can't stop using our
own internal QName class because our QName class needs to be mutable
and the JDK's implementation is not.&nbsp; I'm concerned that this switch
will lead to binary incompatibility problems when methods like this in
XMLTypeFactory<br>
<blockquote>&nbsp; Object createDateTime(String literal);<br>
</blockquote>
change to<br>
<blockquote>&nbsp; XMLGregorianCalendar createDateTime(String literal);<br>
</blockquote>
and of course there will be similar changes for features of these
EDataTypes in existing generated client APIs.<br>
<br>
I'm not sure what's best...&nbsp; Comments are welcome...<br>
<br>
<br>
Brian Vetter wrote:
<blockquote cite="midermdf2$1v1$1@utils.eclipse.org" type="cite">BTW, I
found the problem in my user type where it was losing the
hours/minutes.
<br>
<br>
I'd be more than happy to share it with you if you believe that adding
a special type for datetime is the way to solve the problem.
<br>
<br>
Brian
<br>
<br>
Martin Taal wrote:
<br>
<blockquote type="cite">Brian,
<br>
What class was ic in your case?
<br>
<br>
gr. Martin
<br>
<br>
Brian Vetter wrote:
<br>
<blockquote type="cite">After poking around in the source, I
believe I found the problem in the method isEDate() in
org.eclipse.emf.teneo.util.EcoreDataTypes.java
<br>
<br>
Apparently, the EDataType instance class for date types is of type
Object, not one of the java date classes expected in this function. I
made the following change to the method and was able to get the
datetime mappings I was hoping for, although I didn't try timestamps or
any of the other types. I don't know if there are other places where a
similar change should be made.
<br>
<br>
replace this:
<br>
public boolean isEDate(EDataType eDataType) {
<br>
&nbsp;&nbsp;&nbsp; Class ic = eDataType.getInstanceClass();
<br>
&nbsp;&nbsp;&nbsp; return java.util.Date.class == ic || java.util.Calendar.class == ic
|| java.sql.Date.class == ic;
<br>
}
<br>
<br>
with this:
<br>
public boolean isEDate(EDataType eDataType) {
<br>
&nbsp;&nbsp;&nbsp; String nm = eDataType.getName();
<br>
&nbsp;&nbsp;&nbsp; return nm.equals("DateTime") || nm.equals("Date") ||
nm.equals("Time");
<br>
}
<br>
<br>
When making this change, the hbType() method will now return a
java.util.Date classname instead of null.
<br>
<br>
This results in the correct mapping, but it isn't quite correct. The
problem is that when you populate a dateTime typed element from an XML
file, the format of the data doesn't match what XML Schema expects. I
tried having AbstractMapper.hbType() return
"org.eclipse.xsd.impl.type.XSDDateTimeType" presuming that it could do
the proper mapping, but the hibernate mapping code doesn't know how to
map one of those to a date and tosses an exception.
<br>
<br>
It would appear that what is needed is some kind of user defined type
in the hibernate mapping layer (extending org.hibernate.UserType) but
I'm a bit out over my skis right now. Any suggestions on how to get
this to work properly?
<br>
<br>
Brian
<br>
<br>
Brian Vetter wrote:
<br>
<blockquote type="cite">My date and datetime types are currently
mapping to varchar(255) instead of date. The following XSD element
<br>
<br>
&nbsp;&nbsp;&nbsp; &lt;element name="lastReboot" type="dateTime"&gt;&lt;/element&gt;
<br>
<br>
<br>
maps to the following hbm:
<br>
<br>
&lt;property name="lastReboot" lazy="false" insert="true" update="true"
not-null="false" unique="false"&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;column not-null="false" unique="false" name="`lastreboot`"/&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;type
name=" org.eclipse.emf.teneo.hibernate.mapping.DefaultToStringUserT ype "&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;param name="edatatype"&gt;Date&lt;/param&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;param
name="epackage"&gt;<a class="moz-txt-link-freetext" href="http://www.eclipse.org/emf/2003/XMLType">http://www.eclipse.org/emf/2003/XMLType</a>&lt;/param&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;/type&gt;
<br>
&lt;/property&gt;
<br>
<br>
What is the magic incantation to get this to map to a DateTime. I get
similar results when I use the date type.
<br>
<br>
I'm not sure if this is an XSD-&gt;ecore mapping or a Teneo issue.
<br>
<br>
The ecore mapping looks like:
<br>
&nbsp;&nbsp; &lt;eStructuralFeatures xsi:type="ecore:EAttribute"
name="lastReboot" unique="false"
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; eType="ecore:EDataType
<a class="moz-txt-link-freetext" href="http://www.eclipse.org/emf/2003/XMLType#//DateTime">http://www.eclipse.org/emf/2003/XMLType#//DateTime</a>"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;details key="kind" value="element"/&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;details key="name" value="lastReboot"/&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;details key="namespace" value="##targetNamespace"/&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;/eAnnotations&gt;
<br>
&nbsp;&nbsp; &lt;/eStructuralFeatures&gt;
<br>
<br>
Although it looks like the DateTime type is preserved in the mapping, I
noticed that the ecore-Java mapping is to an Object and not a Date-like
type.
<br>
<br>
Is Date/DateTime not being mapped to DB date/datetime in Teneo or is
there potentially something wrong in my configuration? Brian
<br>
</blockquote>
</blockquote>
<br>
<br>
</blockquote>
</blockquote>
<br>
</body>
</html>

--------------090102080205020907010008--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Teneo] Date and DateTime mapping? [message #602921 is a reply to message #72704] Fri, 23 February 2007 17:24 Go to previous message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
I think if XMLGregorianCalendar had extended Calendar (or GregorianCalendar), it would be more alluring to use directly. The ability for an app to treat it as either would have been useful. Since XMLGregorianCalendar is unrelated, I'm not sure you get any benefit to using it directly.

The safer approach would be to refactor emf's XMLCalendar class to use XMLGregorianCalendar for all of its parsing/serialization features instead of implementing its own.

Brian

Ed Merks wrote:
> Brian,
>
> I'm still looking at using
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=172063 to switch to using
> the XMLGregorianCalendar and Duration now that we can depend on JDK 5.0
> classes. It looks like we can't stop using our own internal QName class
> because our QName class needs to be mutable and the JDK's implementation
> is not. I'm concerned that this switch will lead to binary
> incompatibility problems when methods like this in XMLTypeFactory
>
> Object createDateTime(String literal);
>
> change to
>
> XMLGregorianCalendar createDateTime(String literal);
>
> and of course there will be similar changes for features of these
> EDataTypes in existing generated client APIs.
>
> I'm not sure what's best... Comments are welcome...
>
>
> Brian Vetter wrote:
>> BTW, I found the problem in my user type where it was losing the
>> hours/minutes.
>>
>> I'd be more than happy to share it with you if you believe that adding
>> a special type for datetime is the way to solve the problem.
>>
>> Brian
>>
>>
Re: [Teneo] Date and DateTime mapping? [message #602941 is a reply to message #72692] Sun, 25 February 2007 15:32 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Brian,
Thanks, can you enter a bugzilla for this and attach your patch to it? If possible can you also
attach a small xsd model which illustrates the problem.

gr. Martin

Brian Vetter wrote:
> BTW, I found the problem in my user type where it was losing the
> hours/minutes.
>
> I'd be more than happy to share it with you if you believe that adding a
> special type for datetime is the way to solve the problem.
>
> Brian
>
> Martin Taal wrote:
>> Brian,
>> What class was ic in your case?
>>
>> gr. Martin
>>
>> Brian Vetter wrote:
>>> After poking around in the source, I believe I found the problem in
>>> the method isEDate() in org.eclipse.emf.teneo.util.EcoreDataTypes.java
>>>
>>> Apparently, the EDataType instance class for date types is of type
>>> Object, not one of the java date classes expected in this function. I
>>> made the following change to the method and was able to get the
>>> datetime mappings I was hoping for, although I didn't try timestamps
>>> or any of the other types. I don't know if there are other places
>>> where a similar change should be made.
>>>
>>> replace this:
>>> public boolean isEDate(EDataType eDataType) {
>>> Class ic = eDataType.getInstanceClass();
>>> return java.util.Date.class == ic || java.util.Calendar.class ==
>>> ic || java.sql.Date.class == ic;
>>> }
>>>
>>> with this:
>>> public boolean isEDate(EDataType eDataType) {
>>> String nm = eDataType.getName();
>>> return nm.equals("DateTime") || nm.equals("Date") ||
>>> nm.equals("Time");
>>> }
>>>
>>> When making this change, the hbType() method will now return a
>>> java.util.Date classname instead of null.
>>>
>>> This results in the correct mapping, but it isn't quite correct. The
>>> problem is that when you populate a dateTime typed element from an
>>> XML file, the format of the data doesn't match what XML Schema
>>> expects. I tried having AbstractMapper.hbType() return
>>> "org.eclipse.xsd.impl.type.XSDDateTimeType" presuming that it could
>>> do the proper mapping, but the hibernate mapping code doesn't know
>>> how to map one of those to a date and tosses an exception.
>>>
>>> It would appear that what is needed is some kind of user defined type
>>> in the hibernate mapping layer (extending org.hibernate.UserType) but
>>> I'm a bit out over my skis right now. Any suggestions on how to get
>>> this to work properly?
>>>
>>> Brian
>>>
>>> Brian Vetter wrote:
>>>> My date and datetime types are currently mapping to varchar(255)
>>>> instead of date. 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.DefaultToStringUserT ype ">
>>>> <param name="edatatype">Date</param>
>>>> <param
>>>> name="epackage">http://www.eclipse.org/emf/2003/XMLType</param>
>>>> </type>
>>>> </property>
>>>>
>>>> What is the magic incantation to get this to map to a DateTime. I
>>>> get similar results when I use the date type.
>>>>
>>>> I'm not sure if this is an XSD->ecore mapping or a Teneo issue.
>>>>
>>>> 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 mapping is to an Object and
>>>> not a Date-like type.
>>>>
>>>> Is Date/DateTime not being mapped to DB date/datetime in Teneo or is
>>>> there potentially something wrong in my configuration? Brian
>>
>>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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] Date and DateTime mapping? [message #603034 is a reply to message #72822] Wed, 28 February 2007 21:23 Go to previous message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
I've created bugzilla 175909 and attached 4 files (3 patch files) and one xsd example to it.

Brian

Martin Taal wrote:
> Hi Brian,
> Thanks, can you enter a bugzilla for this and attach your patch to it?
> If possible can you also attach a small xsd model which illustrates the
> problem.
>
> gr. Martin
>
> Brian Vetter wrote:
>> BTW, I found the problem in my user type where it was losing the
>> hours/minutes.
>>
>> I'd be more than happy to share it with you if you believe that adding
>> a special type for datetime is the way to solve the problem.
>>
>> Brian
>>
Previous Topic:[Teneo] Save of resource takes VERY long time
Next Topic:[Teneo] Save of resource takes VERY long time
Goto Forum:
  


Current Time: Tue Oct 20 01:45:43 GMT 2020

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

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

Back to the top