These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Need help on update
PostPosted: Mon May 14, 2007 4:34 pm 
Newbie

Joined: Tue Jan 16, 2007 3:44 pm
Posts: 10
Hi all,

I just began to learn Hibernate. Now I have a problem on update. My update code:
Code:
            Query query = null;
            for (Schedule schedule : schedules) {
               query = session.createQuery(
                  "update Schedule set startTime = :startTime," +
                  "endTime = :endTime, lastUpdatedBy =:updatedBy," +
                  "lastUpdatedOn = :updatedOn where id = :id")
                  .setTimestamp("startTime", schedule.getStartTime())
                  .setTimestamp("endTime", schedule.getEndTime())
                  .setParameter("updatedBy", schedule.getLastUpdatedBy())
                  .setTimestamp("updatedOn", schedule.getLastUpdatedOn())
                  .setParameter("id", schedule.getId());
               query.executeUpdate();
            }

When I run the update code, I always got the following exception, which asked me to set other fields in the Schedule. What I want is just to update partial fields. Should I set all not-null field in the schedule when I update the record. Thank you very much in advance.

Code:
15:06:03,688 INFO  [STDOUT] Hibernate: update CORA.SCHEDULE set START_TIME=?, END_TIME=?, LAST_UPDATED_BY=?, LAST_UPDATED_ON=? where ID=?
15:06:03,844 INFO  [STDOUT] Hibernate: update CORA.SCHEDULE set START_TIME=?, END_TIME=?, LAST_UPDATED_BY=?, LAST_UPDATED_ON=? where ID=?
15:06:03,860 INFO  [STDOUT] Hibernate: select CORA.SQ_SCHEDULE_ID.nextval from dual
15:06:03,875 ERROR [STDERR] org.springframework.dao.DataIntegrityViolationException: not-null property references a null or transient value: com.covance.cora.business.bo.Schedule.studyGroup; nested ex
ception is org.hibernate.PropertyValueException: not-null property references a null or transient value: com.covance.cora.business.bo.Schedule.studyGroup
15:06:03,875 ERROR [STDERR] Caused by:
15:06:03,891 ERROR [STDERR] org.hibernate.PropertyValueException: not-null property references a null or transient value: com.covance.cora.business.bo.Schedule.studyGroup
        at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
        at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:284)
        at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:180)
        at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
        at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
        at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 1:39 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
I believe, it is not Update Query that is causing the problem.
Reason:
i) 2 updates are shown, one at 15:06:03,688 other at 15:06:03,844. If there were errors, the first update would not have gone through.
ii) There is a id fetch ( sequence.nextval ) happening at 15:06:03,860.
iii) DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId() appears in the stack trace.

Form ii and iii it is evident that that some save / update is happening.
Just see if a transient Schedule is saved with null for non nullable fields. ( from some other place )

------------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.