Problems with date type and @Temporal annotation

987 views
Skip to first unread message

Egle Samuleviciute

unread,
Mar 31, 2009, 11:13:22 AM3/31/09
to AribaWeb (aribaweb.org)
Hello,

I am trying to map date type in my entity class to my database but
after using JPA annotation Temporal I get exception.
Code:
@Column(name = "project_deadline")
@Temporal(TemporalType.DATE)
private Date deadline;

Result:

[java] 16:58:52,782 WARN servletadaptor:121 - Servlet Error:
{ ThreadName = "Thread[http-8080-1,5,main]";}, PerformanceState: {}
[java] java.lang.NullPointerException
[java] at
ariba.ui.aribaweb.core.AWConcreteApplication.isHttpSessionCheckedOut
(AWConcreteApplication.java:652)
[java] at
ariba.ui.aribaweb.core.AWConcreteApplication.dispatchRequest
(AWConcreteApplication.java:861)
[java] at
ariba.ui.servletadaptor.AWDispatcherServlet.aribawebDispatcher
(AWDispatcherServlet.java:191)
[java] at ariba.ui.servletadaptor.AWDispatcherServlet.doGet
(AWDispatcherServlet.java:260)
[java] at javax.servlet.http.HttpServlet.service
(HttpServlet.java:617)
[java] at ariba.ui.servletadaptor.AWDispatcherServlet.service
(AWDispatcherServlet.java:80)
[java] at javax.servlet.http.HttpServlet.service
(HttpServlet.java:717)
[java] at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:290)
[java] at
org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:206)
[java] at org.apache.catalina.core.StandardWrapperValve.invoke
(StandardWrapperValve.java:233)
[java] at org.apache.catalina.core.StandardContextValve.invoke
(StandardContextValve.java:191)
[java] at org.apache.catalina.core.StandardHostValve.invoke
(StandardHostValve.java:128)
[java] at org.apache.catalina.valves.ErrorReportValve.invoke
(ErrorReportValve.java:102)
[java] at org.apache.catalina.core.StandardEngineValve.invoke
(StandardEngineValve.java:109)
[java] at org.apache.catalina.connector.CoyoteAdapter.service
(CoyoteAdapter.java:286)
[java] at org.apache.coyote.http11.Http11Processor.process
(Http11Processor.java:845)
[java] at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.process(Http11Protocol.java:583)
[java] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run
(JIoEndpoint.java:447)
[java] at java.lang.Thread.run(Unknown Source)
[java] 16:58:52,782 WARN aribaweb:167 - General warning: **
Error: uncaught exception : java.lang.NullPointerException
[java] at
ariba.ui.aribaweb.core.AWConcreteApplication.isHttpSessionCheckedOut
(AWConcreteApplication.java:652)
[java] at
ariba.ui.aribaweb.core.AWConcreteApplication.dispatchRequest
(AWConcreteApplication.java:861)
[java] at
ariba.ui.servletadaptor.AWDispatcherServlet.aribawebDispatcher
(AWDispatcherServlet.java:191)
[java] at ariba.ui.servletadaptor.AWDispatcherServlet.doGet
(AWDispatcherServlet.java:260)
[java] at javax.servlet.http.HttpServlet.service
(HttpServlet.java:617)
[java] at ariba.ui.servletadaptor.AWDispatcherServlet.service
(AWDispatcherServlet.java:80)
[java] at javax.servlet.http.HttpServlet.service
(HttpServlet.java:717)
[java] at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:290)
[java] at
org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:206)
[java] at org.apache.catalina.core.StandardWrapperValve.invoke
(StandardWrapperValve.java:233)
[java] at org.apache.catalina.core.StandardContextValve.invoke
(StandardContextValve.java:191)
[java] at org.apache.catalina.core.StandardHostValve.invoke
(StandardHostValve.java:128)
[java] at org.apache.catalina.valves.ErrorReportValve.invoke
(ErrorReportValve.java:102)
[java] at org.apache.catalina.core.StandardEngineValve.invoke
(StandardEngineValve.java:109)
[java] at org.apache.catalina.connector.CoyoteAdapter.service
(CoyoteAdapter.java:286)
[java] at org.apache.coyote.http11.Http11Processor.process
(Http11Processor.java:845)
[java] at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.process(Http11Protocol.java:583)
[java] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run
(JIoEndpoint.java:447)
[java] at java.lang.Thread.run(Unknown Source)

-----------------
It's not working without Temporal annotation either. I would really
appreciate any suggestion how could I fix my problem.

Best regards,
Egle

Kingsley

unread,
Mar 31, 2009, 11:42:50 AM3/31/09
to AribaWeb (aribaweb.org)
Hi Egle,

This is not related to any annotation. You can getting null for the
session checkout manager. The init method in AWConcreteApplication
is not getting called. Do you happen to have an application subclass
that overrode init, but didn't call super? You can also breakpoint in
the init method and see if to see if _httpSessionCheckoutManager =
createHttpSessionCheckoutManager(); get executed.

Thanks,
Kingsley

On Mar 31, 8:13 am, Egle Samuleviciute <egle.samulevici...@gmail.com>
wrote:

Eglė Samulevičiūtė

unread,
Mar 31, 2009, 11:53:53 AM3/31/09
to arib...@googlegroups.com
Hello Kingsley,

Thank you for an answer.

Yes, I have a subclass and method in it:

    public void init()
    {
        super.init();
        em = Main.emf.createEntityManager();
        projectList = findProjects();
    }

The reason why I made probably the wrong assumption that the problem was caused by Temporal annotation is that without data field the list of projects that I have is represented fine (no problems in compiling or mapping to database).

Craig Federighi

unread,
Mar 31, 2009, 12:11:41 PM3/31/09
to arib...@googlegroups.com
As it turns out, the full metaui system is not initialized until
*after* init is done being called. Try moving your fetch code to
awake().

- craig

Eglė Samulevičiūtė

unread,
Mar 31, 2009, 12:29:34 PM3/31/09
to arib...@googlegroups.com
Hello,

so I moved the fetch code to awake() function. Unfortunately it did not solved my problem. And so, without Date field in my Entity class, program runs fine.

Eglė Samulevičiūtė

unread,
Mar 31, 2009, 12:32:22 PM3/31/09
to arib...@googlegroups.com
By the way, just to clarify things, could you please shortly describe when init() and awake() should be used?

Craig Federighi

unread,
Mar 31, 2009, 12:32:40 PM3/31/09
to arib...@googlegroups.com
Hi Egle,

Hmm... There's something odd here.

Could you send us a complete source project that reproduces the
problem? (For instance, you could modify the MasterDetail demo
application to recreate the problem, then send us that (after deleting
the build/ directory)).

Thanks,

- craig

Eglė Samulevičiūtė

unread,
Mar 31, 2009, 1:11:24 PM3/31/09
to arib...@googlegroups.com
This is a program with the same issue. The problem accures just when I connect.


Test App with some data.rar

Craig Federighi

unread,
Mar 31, 2009, 1:47:39 PM3/31/09
to arib...@googlegroups.com
Egle,

When I run your example I get this at the tail of the stack trace on startup:
Caused by: org.hibernate.AnnotationException: @Temporal should only be set on a java.util.Date or java.util.Calendar property: model.Project.deadline
	at org.hibernate.cfg.annotations.SimpleValueBinder.setType(SimpleValueBinder.java:93)
	at org.hibernate.cfg.annotations.PropertyBinder.bind(PropertyBinder.java:120)
	at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1667)
	at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:754)
	at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:546)
	at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:291)
	at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
	at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1226)
	at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:191)
	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:253)
Was this exception not visible to you?

Changing ...
import ariba.util.core.Date;
... To
import java.util.Date;

.. fixes the problem.

But then another error is exposed upon clicking the "Create"button:
     [java] Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: model.Project.name
     [java] at org.hibernate.engine.Nullability.checkNullability(Nullability.java:95)
     [java] at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:313)
     [java] at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
     [java] at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
     [java] at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
     [java] at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:154)
     [java] at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:110)
     [java] at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
     [java] at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:645)
     [java] at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:619)
     [java] at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:623)
     [java] at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:220)
     [java] ... 459 more


This is likely due to Hibernate trying to validate the object for insertion in the database upon creation (persist) but before save().  This issue has been discussed extensively on this list (see posts with luxspes) and will hopefully be solved by changing JPAObjectContext to defer the call to persist() until just before save() (rather than on create()).  In the meanwhile, you should probably drop the "nullable = false" annotations.

- craig


On Mar 31, 2009, at 10:11 AM, Eglė Samulevičiūtė wrote:

This is a program with the same issue. The problem accures just when I connect.





<Test App with some data.rar>

Eglė Samulevičiūtė

unread,
Apr 1, 2009, 4:14:53 AM4/1/09
to arib...@googlegroups.com
Dear Craig,

Thank you for taking your time to inspect my issue. I am sorry, yesterday I was in a hurry, that is why in my example Test program that I send you the java.util.Data was missing. In original source I have it. You see, if I comment out one line in my project, it runs normally and has no problem with "nullable = false", so I am not sure if that is really a problem that I am facing here.

Ok, so with this, project runs fine, but my project has no date:

    /*@Column(name = "project_deadline")
    @Temporal(TemporalType.DATE)
    private Date deadline;*/


And like that, I get the following exception:


    @Column(name = "project_deadline")
    @Temporal(TemporalType.DATE)
    private Date deadline;

 [java] INFO: Server startup in 932 ms
     [java] 10:03:54,317  INFO Version:15 - Hibernate Annotations 3.4.0.GA
     [java] 10:03:54,348  INFO Environment:543 - Hibernate 3.3.1.GA
     [java] 10:03:54,363  INFO Environment:576 - hibernate.properties not found
     [java] 10:03:54,363  INFO Environment:709 - Bytecode provider name : javassist
     [java] 10:03:54,379  INFO Environment:627 - using JDK 1.4 java.sql.Timestamp handling
     [java] 10:03:54,535  INFO Version:14 - Hibernate Commons Annotations 3.1.0.GA
     [java] 10:03:54,551  INFO Version:16 - Hibernate EntityManager 3.4.0.GA
     [java] 10:03:55,207  INFO AnnotationBinder:419 - Binding entity from annotated class: backend.Project
     [java] 10:03:55,301  INFO EntityBinder:422 - Bind entity backend.Project on table project
     [java] 01.04.2009 10:03:55 org.apache.catalina.core.ApplicationContext log
     [java] SCHWERWIEGEND: StandardWrapper.Throwable
     [java] ariba.ui.aribaweb.core.AWBinding$AWBindingException: The following exception occurred while evaluating fieldpath: initialize
     [java]     at ariba.ui.aribaweb.core.AWBinding.getBindingException(AWBinding.java:1636)
     [java]     at ariba.ui.aribaweb.core.AWClassAccessorBinding.value(AWBinding.java:802)
     [java]     at ariba.ui.aribaweb.util.AWClasspathResourceDirectory.initJar(AWClasspathResourceDirectory.java:417)
     [java]     at ariba.ui.aribaweb.util.AWClasspathResourceDirectory.autoRegisterJarResources(AWClasspathResourceDirectory.java:320)
     [java]     at ariba.ui.aribaweb.core.AWConcreteServerApplication.registerResourceDirectories(AWConcreteServerApplication.java:329)
     [java]     at ariba.ui.aribaweb.core.AWConcreteServerApplication.init(AWConcreteServerApplication.java:132)
     [java]     at ariba.ui.aribaweb.core.AWConcreteApplication.init(AWConcreteApplication.java:292)
     [java]     at ariba.ui.servletadaptor.AWServletApplication.init(AWServletApplication.java:79)
     [java]     at ariba.ui.aribaweb.core.AWConcreteApplication.createApplication(AWConcreteApplication.java:160)
     [java]     at ariba.ui.servletadaptor.AWDispatcherServlet.createApplication(AWDispatcherServlet.java:66)
     [java]     at ariba.ui.servletadaptor.AWDispatcherServlet.init(AWDispatcherServlet.java:54)
     [java]     at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
     [java]     at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:808)
     [java]     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
     [java]     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
     [java]     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
     [java]     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
     [java]     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
     [java]     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
     [java]     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
     [java]     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
     [java]     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
     [java]     at java.lang.Thread.run(Unknown Source)
-----------------------------------------------------------------------------------------
The question that crossed my mind was how the date is saved? I mean, does date format have anything to do with the way it is saved?

My best regards,
Egle

Craig Federighi

unread,
Apr 1, 2009, 1:34:22 PM4/1/09
to arib...@googlegroups.com
Hi Egle,

The attached modified version of your example works fine for me (with dates).  Please try it out and let us know whether it does not work in your environment.

Thanks,

- craig


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AribaWeb (aribaweb.org)" group.
To post to this group, send email to arib...@googlegroups.com
To unsubscribe from this group, send email to aribaweb+u...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/aribaweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Test.zip

Eglė Samulevičiūtė

unread,
Apr 2, 2009, 5:08:12 AM4/2/09
to arib...@googlegroups.com
Good morning,

The example with date is running fine with database. No exception and I can view the date from database. So I am sorry for taking your time, the problem is somewhere in my project. I just cannot find it at the moment.
Thank you.

Best regards,
Egle

Craig Federighi

unread,
Apr 2, 2009, 9:39:49 AM4/2/09
to arib...@googlegroups.com
Hi Egle,

One thing that I've noticed: certain changes to @Column annotations
(e.g. changing nullable=false to nullable=true) will be changed in the
database by Hibernate's schema update on restart. So, you might want
to try deleting your tables and then restart to build a fresh set.

- craig
Reply all
Reply to author
Forward
0 new messages