-->
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: Update an object
PostPosted: Sat Nov 29, 2008 11:17 am 
Newbie

Joined: Fri Nov 28, 2008 5:11 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2.6

Mapping documents: Quote.hbm.xml
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="microdream.ModulePatient.Library">
<class name="Quote" table="tblquotes">
<composite-id>
<key-property name="name" column="strName" type="string"/>
<key-many-to-one name="clinicalFolder" column="intClinicalFolder"/>
</composite-id>

<property name="description" column="strDescription" type="string" length="500" not-null="false"/>
<property name="dateTime" column="dtaDateTime" type="calendar" update="false" insert="false"/>

<bag name="performanceColls" table="tblperformancechaptersperformance" cascade="save-update" lazy="false" >
<key>
<column name="strNameQuoteOrCare" />
<column name="intClinicalFolder" />
</key>
<one-to-many class="PerformanceColl"/>
</bag>

</class>
</hibernate-mapping>

Mapping documents: PerformanceColl.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="microdream.ModulePatient.Library">
<class name="PerformanceColl" table="tblperformancecolls">
<composite-id>
<key-property name="number" column="intNumber"/>
<key-many-to-one name="quoteOrCare">
<column name="strNameQuoteOrCare" not-null="true"/>
<column name="intClinicalFolder" not-null="true"/>
</key-many-to-one>
</composite-id>

<property name="description" column="strDescription" type="string" length="500"/>

<!--<bag name="performancesCopy" cascade="save-update" lazy="false" >
<key>
<column name="intNumber"/>
<column name="strNameQuoteOrCare"/>
<column name="intClinicalFolder"/>
</key>
<one-to-many class="PerformanceCopy"/>
</bag>-->
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Quote quote = this.currentPatient.getClinicalFolder().getQuotes().get(0);

Session session = HibernateUtil.currentSession();
session.beginTransaction();

PerformanceColl perfColl = quote.getPerformanceColls().get(1);

//Remove
quote.getPerformanceColls().remove(perfColl);

session.update(quote);
session.getTransaction().commit();
session.close();

Full stack trace of any exception that occurs:
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:170)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at microdream.modulepatient.TestHibernate.testRemovePerfCopyFromPerfColl(TestHibernate.java:72)
Caused by: java.sql.BatchUpdateException: Column 'strNameQuoteOrCare' cannot be null
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1669)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1085)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)



Name and version of the database you are using:
MySql 5.0.51

The generated SQL (show_sql=true):
select
patient0_.intPersonId as intId24_,
patient0_1_.strFirstName as strFirst2_24_,
patient0_1_.strLastName as strLastN3_24_,
patient0_1_.dtaBirthDate as dtaBirth4_24_,
patient0_1_.intIdNationality as intIdNat5_24_,
patient0_1_.strPhone as strPhone24_,
patient0_1_.strFax as strFax24_,
patient0_1_.strPhoneOffice as strPhone8_24_,
patient0_1_.strCellular as strCellu9_24_,
patient0_1_.strFirstLastNameSpouse as strFirs10_24_,
patient0_1_.intIdCivilState as intIdCi11_24_,
patient0_1_.intIdAddress as intIdAd12_24_,
patient0_1_.isMan as isMan24_,
patient0_1_.dtaCreationDate as dtaCrea14_24_,
patient0_1_.dtaLastModify as dtaLast15_24_,
patient0_.bloPersonalBild as bloPerso2_25_,
patient0_.strTutorFirstName as strTutor3_25_,
patient0_.strTutorLastName as strTutor4_25_,
patient0_.strRelationshipDegree as strRelat5_25_,
patient0_.strTutorAddress as strTutor6_25_,
patient0_.strNotes as strNotes25_,
patient0_.strProfession as strProfe8_25_,
patient0_.strHealthInsuranceName as strHealt9_25_,
patient0_.strHealthClientNumber as strHeal10_25_,
patient0_.intIdClinicFolder as intIdCl11_25_
from
tblpatients patient0_
inner join
tblpeople patient0_1_
on patient0_.intPersonId=patient0_1_.intId
where
patient0_.intPersonId=37
Hibernate:
select
clinicalfo0_.intId as intId3_1_,
clinicalfo0_.intIdRootFolder as intIdRoo2_3_1_,
patient1_.intPersonId as intId24_0_,
patient1_1_.strFirstName as strFirst2_24_0_,
patient1_1_.strLastName as strLastN3_24_0_,
patient1_1_.dtaBirthDate as dtaBirth4_24_0_,
patient1_1_.intIdNationality as intIdNat5_24_0_,
patient1_1_.strPhone as strPhone24_0_,
patient1_1_.strFax as strFax24_0_,
patient1_1_.strPhoneOffice as strPhone8_24_0_,
patient1_1_.strCellular as strCellu9_24_0_,
patient1_1_.strFirstLastNameSpouse as strFirs10_24_0_,
patient1_1_.intIdCivilState as intIdCi11_24_0_,
patient1_1_.intIdAddress as intIdAd12_24_0_,
patient1_1_.isMan as isMan24_0_,
patient1_1_.dtaCreationDate as dtaCrea14_24_0_,
patient1_1_.dtaLastModify as dtaLast15_24_0_,
patient1_.bloPersonalBild as bloPerso2_25_0_,
patient1_.strTutorFirstName as strTutor3_25_0_,
patient1_.strTutorLastName as strTutor4_25_0_,
patient1_.strRelationshipDegree as strRelat5_25_0_,
patient1_.strTutorAddress as strTutor6_25_0_,
patient1_.strNotes as strNotes25_0_,
patient1_.strProfession as strProfe8_25_0_,
patient1_.strHealthInsuranceName as strHealt9_25_0_,
patient1_.strHealthClientNumber as strHeal10_25_0_,
patient1_.intIdClinicFolder as intIdCl11_25_0_
from
tblclinicalfolders clinicalfo0_
left outer join
tblpatients patient1_
on clinicalfo0_.intId=patient1_.intPersonId
left outer join
tblpeople patient1_1_
on patient1_.intPersonId=patient1_1_.intId
where
clinicalfo0_.intId=?
Hibernate:
select
quotes0_.intClinicalFolder as intClini2_1_,
quotes0_.strName as strName1_,
quotes0_.strName as strName26_0_,
quotes0_.intClinicalFolder as intClini2_26_0_,
quotes0_.strDescription as strDescr3_26_0_,
quotes0_.dtaDateTime as dtaDateT4_26_0_
from
tblquotes quotes0_
where
quotes0_.intClinicalFolder=?
Hibernate:
select
performanc0_.strNameQuoteOrCare as strNameQ2_1_,
performanc0_.intClinicalFolder as intClini3_1_,
performanc0_.intNumber as intNumber1_,
performanc0_.intNumber as intNumber21_0_,
performanc0_.strNameQuoteOrCare as strNameQ2_21_0_,
performanc0_.intClinicalFolder as intClini3_21_0_,
performanc0_.strDescription as strDescr4_21_0_
from
tblperformancecolls performanc0_
where
performanc0_.strNameQuoteOrCare=?
and performanc0_.intClinicalFolder=?
Hibernate:
update
tblperformancecolls
set
strNameQuoteOrCare=null,
intClinicalFolder=null
where
strNameQuoteOrCare=?
and intClinicalFolder=?
and intNumber=?
and strNameQuoteOrCare=?
and intClinicalFolder=?
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 3.562 sec

------------- Standard Output ---------------
Hibernate:
select
patient0_.intPersonId as intId24_,
patient0_1_.strFirstName as strFirst2_24_,
patient0_1_.strLastName as strLastN3_24_,
patient0_1_.dtaBirthDate as dtaBirth4_24_,
patient0_1_.intIdNationality as intIdNat5_24_,
patient0_1_.strPhone as strPhone24_,
patient0_1_.strFax as strFax24_,
patient0_1_.strPhoneOffice as strPhone8_24_,
patient0_1_.strCellular as strCellu9_24_,
patient0_1_.strFirstLastNameSpouse as strFirs10_24_,
patient0_1_.intIdCivilState as intIdCi11_24_,
patient0_1_.intIdAddress as intIdAd12_24_,
patient0_1_.isMan as isMan24_,
patient0_1_.dtaCreationDate as dtaCrea14_24_,
patient0_1_.dtaLastModify as dtaLast15_24_,
patient0_.bloPersonalBild as bloPerso2_25_,
patient0_.strTutorFirstName as strTutor3_25_,
patient0_.strTutorLastName as strTutor4_25_,
patient0_.strRelationshipDegree as strRelat5_25_,
patient0_.strTutorAddress as strTutor6_25_,
patient0_.strNotes as strNotes25_,
patient0_.strProfession as strProfe8_25_,
patient0_.strHealthInsuranceName as strHealt9_25_,
patient0_.strHealthClientNumber as strHeal10_25_,
patient0_.intIdClinicFolder as intIdCl11_25_
from
tblpatients patient0_
inner join
tblpeople patient0_1_
on patient0_.intPersonId=patient0_1_.intId
where
patient0_.intPersonId=37
Hibernate:
select
clinicalfo0_.intId as intId3_1_,
clinicalfo0_.intIdRootFolder as intIdRoo2_3_1_,
patient1_.intPersonId as intId24_0_,
patient1_1_.strFirstName as strFirst2_24_0_,
patient1_1_.strLastName as strLastN3_24_0_,
patient1_1_.dtaBirthDate as dtaBirth4_24_0_,
patient1_1_.intIdNationality as intIdNat5_24_0_,
patient1_1_.strPhone as strPhone24_0_,
patient1_1_.strFax as strFax24_0_,
patient1_1_.strPhoneOffice as strPhone8_24_0_,
patient1_1_.strCellular as strCellu9_24_0_,
patient1_1_.strFirstLastNameSpouse as strFirs10_24_0_,
patient1_1_.intIdCivilState as intIdCi11_24_0_,
patient1_1_.intIdAddress as intIdAd12_24_0_,
patient1_1_.isMan as isMan24_0_,
patient1_1_.dtaCreationDate as dtaCrea14_24_0_,
patient1_1_.dtaLastModify as dtaLast15_24_0_,
patient1_.bloPersonalBild as bloPerso2_25_0_,
patient1_.strTutorFirstName as strTutor3_25_0_,
patient1_.strTutorLastName as strTutor4_25_0_,
patient1_.strRelationshipDegree as strRelat5_25_0_,
patient1_.strTutorAddress as strTutor6_25_0_,
patient1_.strNotes as strNotes25_0_,
patient1_.strProfession as strProfe8_25_0_,
patient1_.strHealthInsuranceName as strHealt9_25_0_,
patient1_.strHealthClientNumber as strHeal10_25_0_,
patient1_.intIdClinicFolder as intIdCl11_25_0_
from
tblclinicalfolders clinicalfo0_
left outer join
tblpatients patient1_
on clinicalfo0_.intId=patient1_.intPersonId
left outer join
tblpeople patient1_1_
on patient1_.intPersonId=patient1_1_.intId
where
clinicalfo0_.intId=?
Hibernate:
select
quotes0_.intClinicalFolder as intClini2_1_,
quotes0_.strName as strName1_,
quotes0_.strName as strName26_0_,
quotes0_.intClinicalFolder as intClini2_26_0_,
quotes0_.strDescription as strDescr3_26_0_,
quotes0_.dtaDateTime as dtaDateT4_26_0_
from
tblquotes quotes0_
where
quotes0_.intClinicalFolder=?
Hibernate:
select
performanc0_.strNameQuoteOrCare as strNameQ2_1_,
performanc0_.intClinicalFolder as intClini3_1_,
performanc0_.intNumber as intNumber1_,
performanc0_.intNumber as intNumber21_0_,
performanc0_.strNameQuoteOrCare as strNameQ2_21_0_,
performanc0_.intClinicalFolder as intClini3_21_0_,
performanc0_.strDescription as strDescr4_21_0_
from
tblperformancecolls performanc0_
where
performanc0_.strNameQuoteOrCare=?
and performanc0_.intClinicalFolder=?
Hibernate:
update
tblperformancecolls
set
strNameQuoteOrCare=null,
intClinicalFolder=null
where
strNameQuoteOrCare=?
and intClinicalFolder=?
and intNumber=?
and strNameQuoteOrCare=?
and intClinicalFolder=?

Problem:

Because Hibernate set the following columns strNameQuoteOrCare and intClinicalFolder to null when I have specify in the mapping class PerformanceColl not-null=true:

update
tblperformancecolls
set
strNameQuoteOrCare=null,
intClinicalFolder=null
where
strNameQuoteOrCare=?
and intClinicalFolder=?
and intNumber=?
and strNameQuoteOrCare=?
and intClinicalFolder=?

Best Regards

Rino


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2008 6:02 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
What do you expect to happen when you remove the PerformanceColl object from the Quote?

If you want to delete it you could:

Code:
session.delete(perfColl);


If you want to keep it, you need to allow null values in the strNameQuoteOrCare and intClinicalFolder column.


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.