karishma-tirthani / odata4j

Automatically exported from code.google.com/p/odata4j
0 stars 0 forks source link

org.odata4j.internal.TypeConverter breaks with java.sql.Date properties #130

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Map a table with a date column in the model class as:

    @Temporal(TemporalType.DATE)
    protected java.util.Date createdOn;

2. Add a row to that table with a non-null date value.
3. Issue an OData GET request via a web browser for items in that table.

What is the expected output? What do you see instead?
-----------------------------------------------------
I expect to get query results. However I get an exception instead as follows:

java.lang.RuntimeException: java.lang.IllegalArgumentException
    at org.odata4j.producer.jpa.JPAProducer.jpaEntityToOEntity(JPAProducer.java:416)
    at org.odata4j.producer.jpa.JPAProducer.makeEntity(JPAProducer.java:189)
    at org.odata4j.producer.jpa.JPAProducer.access$400(JPAProducer.java:75)
    at org.odata4j.producer.jpa.JPAProducer$5.apply(JPAProducer.java:605)
    at org.odata4j.producer.jpa.JPAProducer$5.apply(JPAProducer.java:603)
    at org.core4j.Enumerable$FuncIterator.next(Enumerable.java:491)
    at org.core4j.Enumerable.toList(Enumerable.java:65)
    at org.odata4j.producer.jpa.JPAProducer.getEntitiesResponse(JPAProducer.java:601)
    at org.odata4j.producer.jpa.JPAProducer.getEntities(JPAProducer.java:199)
    at org.odata4j.producer.jpa.JPAProducer.access$100(JPAProducer.java:75)
    at org.odata4j.producer.jpa.JPAProducer$2.apply(JPAProducer.java:139)
    at org.odata4j.producer.jpa.JPAProducer$2.apply(JPAProducer.java:137)
    at org.odata4j.producer.jpa.JPAProducer.common(JPAProducer.java:246)
    at org.odata4j.producer.jpa.JPAProducer.getEntities(JPAProducer.java:136)
    at org.odata4j.producer.resources.EntitiesRequestResource.getEntities(EntitiesRequestResource.java:126)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.IllegalArgumentException
    at java.sql.Date.getHours(Date.java:177)
    at org.joda.time.LocalDateTime.fromDateFields(LocalDateTime.java:234)
    at org.odata4j.internal.TypeConverter.convert(TypeConverter.java:83)
    at org.odata4j.core.OSimpleObjects.create(OSimpleObjects.java:53)
    at org.odata4j.core.OProperties.simple(OProperties.java:51)
    at org.odata4j.producer.jpa.JPAProducer.jpaEntityToOEntity(JPAProducer.java:291)
    ... 45 more

What version of the product are you using? On what operating system?
-------------------------------------------------------------------
I am using odata4j version 0.5 (the download link on 
http://code.google.com/p/odata4j/)

Please provide any additional information below.
------------------------------------------------

From what I can tell the issue is due jodatime treating sqldate as a date but 
sqldate does not have any time information, only day,month and year.

Original issue reported on code.google.com by re...@therobinsons.gen.nz on 18 Jan 2012 at 11:00

GoogleCodeExporter commented 8 years ago
Changing @Temporal(TemporalType.DATE) to @Temporal(TemporalType.TIMESTAMP) 
fixes the issue. However in my opinion it should handle the 
@Temporal(TemporalType.DATE) attribute as well.

Original comment by re...@therobinsons.gen.nz on 6 Feb 2012 at 5:15

GoogleCodeExporter commented 8 years ago

Original comment by philipp.sebastian.thun on 27 Mar 2012 at 5:23

GoogleCodeExporter commented 8 years ago
Could be reproduced with Hibernate as JPA provider. Fixed with revision 
5e6ea6c13265.

Original comment by philipp.sebastian.thun on 10 Apr 2012 at 12:48