Announcement Announcement Module
Collapse
No announcement yet.
Use of java.sql.Timestamp in field command Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Use of java.sql.Timestamp in field command

    I am new to Roo and most of the rest of Spring.

    I am learning Roo, and I was trying to create an entity that has a Timestamp for storing date/time information. Using the Roo Shell in a terminal window (on a Mac, 10.6.7) I created an entity and then used this command to add the field:

    ~.entities.MetaDataAttribute roo> field date --type java.sql.Timestamp --fieldName testDate

    Which had this output:

    Updated SRC_MAIN_JAVA/com/example/datahub/entities/MetaDataAttribute.java
    Updated SRC_MAIN_JAVA/com/example/datahub/entities/MetaDataAttribute_Roo_ToString.aj
    Updated SRC_MAIN_JAVA/com/example/datahub/entities/MetaDataAttribute_Roo_JavaBean.aj
    Updated SRC_TEST_JAVA/com/example/datahub/entities/MetaDataAttributeDataOnDemand_Roo_DataOnDemand.aj

    Which produced this code:

    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(style = "S-")
    private Timestamp testDate;

    Then when I went to run the tests, I got this exception:

    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'transactionManager' defined in class path resource [META-INF/spring/applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in class path resource [META-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: @Temporal should only be set on a java.util.Date or java.util.Calendar property: com.example.datahub.entities.MetaDataAttribute.tes tDate

    Now it looks to me like I can't use a timestamp to be my date/time field (and I am fine with that) but what I wonder about is why didn't roo give me a warning when I ran the 'field' command? When I went to run another such command and tried using the command completion it didn't want to complete the command for me (which was a hint, albeit after the fact).

    Is this a bug or is this by design?

    Thanks!

  • #2
    I'm experiencing the same problem: "@Temporal should only be set on a java.util.Date or java.util.Calendar".

    Code:
    2011-09-01 10:57:51,076 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in URL [jar:file:/C:/XXX/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/XXX/WEB-INF/lib/XXX-3.0.0.jar!/META-INF/spring/applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [jar:file:/C:/XXX/.metadata/.plugins/org.eclipse.wst.server.core/XXX-web/WEB-INF/lib/XXX-3.0.0.jar!/META-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: @Temporal should only be set on a java.util.Date or java.util.Calendar property: myPackage.MyClass.myTimestamp
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205)
    	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)
    	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
    	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
    	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:623)
    	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:675)
    	at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:601)
    	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
    	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1320)
    	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
    	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1061)
    	at org.apache.catalina.core.StandardHost.start(StandardHost.java:862)
    	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    	at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    	at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    	at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:618)
    	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [jar:file:...
    ...
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [jar:file:...
    ...
    Caused by: org.hibernate.AnnotationException: @Temporal should only be set on a java.util.Date or java.util.Calendar property: myPackage.MyClass.myTimestamp
    	at org.hibernate.cfg.annotations.SimpleValueBinder.setType(SimpleValueBinder.java:147)
    	at org.hibernate.cfg.annotations.PropertyBinder.makePropertyAndValue(PropertyBinder.java:185)
    	at org.hibernate.cfg.annotations.PropertyBinder.makePropertyValueAndBind(PropertyBinder.java:200)
    	at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:2061)
    	at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:796)
    	at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:707)
    	at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3977)
    	at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3931)
    	at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1368)
    	at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1345)
    	at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1477)
    	at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
    	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1096)
    	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:685)
    	at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
    	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
    	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
    	... 46 more
    
    I'm using Roo 1.1.5 within STS 2.7.1 with IBM RAD 7 JDK (Java SE 5) in windows.

    The web project uses Hibernate (3.6.1.Final) as ORM and DB2 as Database.

    According https://github.com/hibernate/hiberna...lueBinder.java it's true that Hibernate doesn't allow other than java.util.Date or java.util.Calendar (see line 147, as the stack trace informs)

    I agree montgomery_burns (excellent! [sorry ]), in order to facilitate a Rapid development, this kind of issues should be at least informed.

    If it's feasible to make this modification, I can raise a JIRA ticket, if not (because the problem is only Hibernate related) thanks for reading my response.

    Do you have a suggestion for workaround this problems? Since the database column is a Timestamp, I need the whole data loaded. I think I'll try with a persistent String and a transient Timestamp.

    Regards.
    Last edited by jbbarquero; Sep 1st, 2011, 06:42 AM. Reason: Privacy

    Comment


    • #3
      Please raise a bug request for this. OpenJPA does not appear to have the problem, however the reference JPA 2.0 implementation, EclipseLink also shows the issue, so it should be fixed

      Comment


      • #4
        https://jira.springsource.org/browse/ROO-2689 raised and resolved

        Comment


        • #5
          Apologies for the delay and thank you very much for creating and resolving the issue.

          I tried to investigate a little more because I though another Entites were working with Timestamps, because they are for tables containing a column with such data type.

          I was wrong, a java.sql.Date was used instead. Now I wonder if nobody else is using Timestamps.

          Thanks again.

          Comment

          Working...
          X