Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » [Teneo] Date and DateTime mapping?
|
Re: [Teneo] Date and DateTime mapping? [message #72651 is a reply to message #72637] |
Thu, 22 February 2007 23:49 |
Brian Vetter 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 |
Martin Taal 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 |
Brian Vetter 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 |
Brian Vetter 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 |
Eclipse User |
|
|
|
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. 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<br>
<blockquote> Object createDateTime(String literal);<br>
</blockquote>
change to<br>
<blockquote> 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... 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>
Class ic = eDataType.getInstanceClass();
<br>
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>
String nm = eDataType.getName();
<br>
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>
<element name="lastReboot" type="dateTime"></element>
<br>
<br>
<br>
maps to the following hbm:
<br>
<br>
<property name="lastReboot" lazy="false" insert="true" update="true"
not-null="false" unique="false">
<br>
<column not-null="false" unique="false" name="`lastreboot`"/>
<br>
<type
name=" org.eclipse.emf.teneo.hibernate.mapping.DefaultToStringUserT ype ">
<br>
<param name="edatatype">Date</param>
<br>
<param
name="epackage"><a class="moz-txt-link-freetext" href="http://www.eclipse.org/emf/2003/XMLType">http://www.eclipse.org/emf/2003/XMLType</a></param>
<br>
</type>
<br>
</property>
<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->ecore mapping or a Teneo issue.
<br>
<br>
The ecore mapping looks like:
<br>
<eStructuralFeatures xsi:type="ecore:EAttribute"
name="lastReboot" unique="false"
<br>
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>">
<br>
<eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>>
<br>
<details key="kind" value="element"/>
<br>
<details key="name" value="lastReboot"/>
<br>
<details key="namespace" value="##targetNamespace"/>
<br>
</eAnnotations>
<br>
</eStructuralFeatures>
<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 #72822 is a reply to message #72692] |
Sun, 25 February 2007 15:32 |
Martin Taal 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 #602900 is a reply to message #72637] |
Thu, 22 February 2007 23:49 |
Brian Vetter 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 |
Martin Taal 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 |
Brian Vetter 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 |
Brian Vetter 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 |
Ed Merks Messages: 33140 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. 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<br>
<blockquote> Object createDateTime(String literal);<br>
</blockquote>
change to<br>
<blockquote> 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... 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>
Class ic = eDataType.getInstanceClass();
<br>
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>
String nm = eDataType.getName();
<br>
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>
<element name="lastReboot" type="dateTime"></element>
<br>
<br>
<br>
maps to the following hbm:
<br>
<br>
<property name="lastReboot" lazy="false" insert="true" update="true"
not-null="false" unique="false">
<br>
<column not-null="false" unique="false" name="`lastreboot`"/>
<br>
<type
name=" org.eclipse.emf.teneo.hibernate.mapping.DefaultToStringUserT ype ">
<br>
<param name="edatatype">Date</param>
<br>
<param
name="epackage"><a class="moz-txt-link-freetext" href="http://www.eclipse.org/emf/2003/XMLType">http://www.eclipse.org/emf/2003/XMLType</a></param>
<br>
</type>
<br>
</property>
<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->ecore mapping or a Teneo issue.
<br>
<br>
The ecore mapping looks like:
<br>
<eStructuralFeatures xsi:type="ecore:EAttribute"
name="lastReboot" unique="false"
<br>
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>">
<br>
<eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>>
<br>
<details key="kind" value="element"/>
<br>
<details key="name" value="lastReboot"/>
<br>
<details key="namespace" value="##targetNamespace"/>
<br>
</eAnnotations>
<br>
</eStructuralFeatures>
<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 #602941 is a reply to message #72692] |
Sun, 25 February 2007 15:32 |
Martin Taal 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
|
|
| |
Goto Forum:
Current Time: Wed Apr 24 21:38:49 GMT 2024
Powered by FUDForum. Page generated in 0.05135 seconds
|