-->
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: prob on composite-id, a rare scenario i guess.. pls help me
PostPosted: Mon Apr 04, 2005 12:37 pm 
Newbie

Joined: Mon Apr 04, 2005 10:51 am
Posts: 1
hello everyone,

i got a problem with an application i am developing. the case which i guess perhaps is a rare one goes like this:

this is the mapping segment i have a problem with:


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

<hibernate-mapping package="mil.pis.model.genInfo.milInfo">
<class name="Accreditation" table="TR_ACCREDITATION">
<composite-id name="id" class="mil.pis.model.genInfo.milInfo.AccreditationPK" >
<key-many-to-one name="afpsn" class="mil.pis.model.commons.Master" >
<column name="AFPSN" length="15" />
</key-many-to-one>

<!-- this code in red is the part i am having trouble with -->
<key-many-to-one name="courseCode" class="mil.pis.model.commons.MilCourseCode">
<column name="CourseCode" length="15" />
</key-many-to-one>
<key-many-to-one name="asCourseCode" class="mil.pis.model.commons.MilCourseCode">
<column name="AsCourseCode" length="15"/>
</key-many-to-one>


</composite-id>

<!-- associations -->
</class>


the table schema for accreditation is:

-- Table: tr_accreditation

-- DROP TABLE tr_accreditation;

CREATE TABLE tr_accreditation
(
afpsn varchar(15) NOT NULL,
coursecode varchar(15) NOT NULL,
ascoursecode varchar(15) NOT NULL,
"type" varchar(15),
authority varchar(50),
effectivitydate date,
cnastatus varchar(1),
cnaauthority varchar(50),
cnaremarks varchar(50),
userid varchar(50),
datelastupdate date,
reccreatedby varchar(15),
recdatecreated date,
CONSTRAINT tr_accreditation_pkey PRIMARY KEY (afpsn, coursecode, ascoursecode),
CONSTRAINT fk_tr_accreditation_rf_milcoursecode FOREIGN KEY (coursecode) REFERENCES rf_milcoursecode (coursecode) ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_tr_accreditation_rf_milcoursecode1 FOREIGN KEY (ascoursecode) REFERENCES rf_milcoursecode (coursecode) ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_tr_accreditation_tr_master FOREIGN KEY (afpsn) REFERENCES tr_master (afpsn) ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH OIDS;
ALTER TABLE tr_accreditation OWNER TO postgres;


and for milCourseCode is:

-- Table: rf_milcoursecode

-- DROP TABLE rf_milcoursecode;

CREATE TABLE rf_milcoursecode
(
coursecode varchar(15) NOT NULL,
coursedescription varchar(60),
noofhours int2,
trainingtype varchar(15),
reccreatedby varchar(15),
recdatecreated date,
userid varchar(15),
datelastupdate date,
CONSTRAINT pk_rf_milcoursecode PRIMARY KEY (coursecode)
)
WITH OIDS;
ALTER TABLE rf_milcoursecode OWNER TO postgres;


if i save a record with an afpsn for example set to "12345", coursecode="cc1" and ascoursecode="ac1" together with other associations, it would save successfully if it is the first time that afpsn value is saved. but when i tried to save another record using the same afpsn and different coursecode and ascoursecode, the following error occurs:

Hibernate: insert into TR_ACCREDITATION (Type, Authority, EffectivityDate, CNAStatus, CNAAuthority, CNARemarks, UserID, DateLastUpdate, RecCreatedBy, RecDateCreated, AFPSN, CourseCode, AsCourseCode) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2005-04-04 22:28:26,268 WARN [net.sf.hibernate.util.JDBCExceptionReporter] - <SQL Error: 0, SQLState: null>
2005-04-04 22:28:26,269 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] - <Batch entry 0 insert into TR_ACCREDITATION (Type, Authority, EffectivityDate, CNAStatus, CNAAuthority, CNARemarks, UserID, DateLastUpdate, RecCreatedBy, RecDateCreated, AFPSN, CourseCode, AsCourseCode) values ( was aborted. Call getNextException() to see the cause.>
2005-04-04 22:28:26,269 WARN [net.sf.hibernate.util.JDBCExceptionReporter] - <SQL Error: 0, SQLState: 23503>
2005-04-04 22:28:26,269 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] - <ERROR: insert or update on table "tr_accreditation" violates foreign key constraint "fk_tr_accreditation_rf_milcoursecode"
>
2005-04-04 22:28:26,274 WARN [net.sf.hibernate.util.JDBCExceptionReporter] - <SQL Error: 0, SQLState: null>
2005-04-04 22:28:26,275 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] - <Batch entry 0 insert into TR_ACCREDITATION (Type, Authority, EffectivityDate, CNAStatus, CNAAuthority, CNARemarks, UserID, DateLastUpdate, RecCreatedBy, RecDateCreated, AFPSN, CourseCode, AsCourseCode) values ( was aborted. Call getNextException() to see the cause.>
2005-04-04 22:28:26,275 WARN [net.sf.hibernate.util.JDBCExceptionReporter] - <SQL Error: 0, SQLState: 23503>
2005-04-04 22:28:26,275 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] - <ERROR: insert or update on table "tr_accreditation" violates foreign key constraint "fk_tr_accreditation_rf_milcoursecode"
>
2005-04-04 22:28:26,296 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] - <Could not execute JDBC batch update>
Batch entry 0 insert into TR_ACCREDITATION (Type, Authority, EffectivityDate, CNAStatus, CNAAuthority, CNARemarks, UserID, DateLastUpdate, RecCreatedBy, RecDateCreated, AFPSN, CourseCode, AsCourseCode) values ( was aborted. Call getNextException() to see the cause.
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:107)
at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:126)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2421)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2371)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at org.springframework.orm.hibernate.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:214)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:177)
at org.springframework.orm.hibernate.HibernateTemplate.save(HibernateTemplate.java:298)
at mil.pis.dao.hibernate.genInfo.milInfo.AccreditationDAOHibernate.saveAccreditation(AccreditationDAOHibernate.java:57)
at mil.pis.web.genInfo.milInfo.AccreditationHandler.saveAccreditation(AccreditationHandler.java:81)
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:585)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
at javax.faces.component.UICommand.broadcast(UICommand.java:312)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:595)
2005-04-04 22:28:26,309 ERROR [net.sf.hibernate.impl.SessionImpl] - <Could not synchronize database state with session>
net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:133)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2421)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2371)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at org.springframework.orm.hibernate.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:214)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:177)
at org.springframework.orm.hibernate.HibernateTemplate.save(HibernateTemplate.java:298)
at mil.pis.dao.hibernate.genInfo.milInfo.AccreditationDAOHibernate.saveAccreditation(AccreditationDAOHibernate.java:57)
at mil.pis.web.genInfo.milInfo.AccreditationHandler.saveAccreditation(AccreditationHandler.java:81)
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:585)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
at javax.faces.component.UICommand.broadcast(UICommand.java:312)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:595)
Caused by: Batch entry 0 insert into TR_ACCREDITATION (Type, Authority, EffectivityDate, CNAStatus, CNAAuthority, CNARemarks, UserID, DateLastUpdate, RecCreatedBy, RecDateCreated, AFPSN, CourseCode, AsCourseCode) values ( was aborted. Call getNextException() to see the cause.
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:107)
at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:126)
... 45 more
2005-04-04 22:28:26,341 WARN [org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator] - <Unable to translate SQLException with errorCode '0', will now try the fallback translator>
2005-04-04 22:28:26,342 INFO [org.springframework.jdbc.support.SQLStateSQLExceptionTranslator] - <Translating SQLException with SQLState 'null' and errorCode '0' and message [Batch entry 0 insert into TR_ACCREDITATION (Type, Authority, EffectivityDate, CNAStatus, CNAAuthority, CNARemarks, UserID, DateLastUpdate, RecCreatedBy, RecDateCreated, AFPSN, CourseCode, AsCourseCode) values ( was aborted. Call getNextException() to see the cause.]; SQL was [] for task [Hibernate operation]>
2005-04-04 22:33:19,537 INFO [de.mindmatters.faces.spring.FacesSpringVariableResolver$FacesWebApplicationContext] - <Closing application context [Root XmlWebApplicationContext]>
2005-04-04 22:33:19,550 INFO [de.mindmatters.faces.spring.FacesSpringVariableResolver$FacesListableBeanFactory] - <Destroying singletons in factory {de.mindmatters.faces.spring.FacesSpringVariableResolver$FacesListableBeanFactory defining beans [postOperationAlerter,sessionObjectsHandler,homeView,homeMenu,genInfoView,genInfoMenu,milOrdersView,milOrdersMenu,genOrdersView,genOrdersMenu,addGenOrdersView,addGenOrdersSubViews,addMasterSubView,addSectionSubView,viewGenOrdersView,viewGenOrdersSubViews,viewMasterSubView,viewDetailedSubView,viewSectionSubView,viewListingSubView,specialOrdersView,specialOrdersSubViews,viewListingSpecialSubView,addSecParaTabbedView,goMasterListHandler,goSecParaHandler,milInfoView,milInfoMenu,addMilInfoView,addMilInfoSubViews,addMilRecordsSubView,viewMilInfoView,viewMilInfoSubViews,milListingSubView,accreditationHandler,afposmosHandler,unitCodeLookupHandler]; parent=<org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [accreditationDAOHibernate,accreditationID,accreditation,afposmosDAOHibernate,afposmosID,afposmos,goMasterListDAO,goMasterListID,goMasterList,goSecParaDAO,goSecParaID,goSecPara,goSecParaDetailed,goRedesignationOfUnitID,goRedesignationOfUnit,goLongevityPayID,goLongevityPay,goCCNAID,goCCNA,goAccreditationID,goAccreditation,goAbsorbtionOfUnitID,goAbsorbtionOfUnit,goActivationOfUnitID,goActivationOfUnit,goDeactivationOfUnitID,goDeactivationOfUnit,goDutyAssignmentID,goDutyAssignment,goLineOfDutyStatusID,goLineOfDutyStatus,goChangeOfNameID,goChangeOfName,goProDemID,goProDem,goAwardsID,goAwards,propertyConfigurer,myDataSource,mySessionFactory,unitCode,afposmosCode,dutyCode,geographicalCode,leaveCode,perGroupName,preEntryCode,rankCode,separationCode,sourceCommCode,dutyModeCode,milCourseCode,milSchoolCode,awardCode,master,civeligibility,lineOfDutyStatus,unitCodeDAO]; Root of BeanFactory hierarchy>}>
2005-04-04 22:33:19,567 INFO [org.springframework.web.context.support.XmlWebApplicationContext] - <Closing application context [Root XmlWebApplicationContext]>
2005-04-04 22:33:19,568 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Destroying singletons in factory {org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [accreditationDAOHibernate,accreditationID,accreditation,afposmosDAOHibernate,afposmosID,afposmos,goMasterListDAO,goMasterListID,goMasterList,goSecParaDAO,goSecParaID,goSecPara,goSecParaDetailed,goRedesignationOfUnitID,goRedesignationOfUnit,goLongevityPayID,goLongevityPay,goCCNAID,goCCNA,goAccreditationID,goAccreditation,goAbsorbtionOfUnitID,goAbsorbtionOfUnit,goActivationOfUnitID,goActivationOfUnit,goDeactivationOfUnitID,goDeactivationOfUnit,goDutyAssignmentID,goDutyAssignment,goLineOfDutyStatusID,goLineOfDutyStatus,goChangeOfNameID,goChangeOfName,goProDemID,goProDem,goAwardsID,goAwards,propertyConfigurer,myDataSource,mySessionFactory,unitCode,afposmosCode,dutyCode,geographicalCode,leaveCode,perGroupName,preEntryCode,rankCode,separationCode,sourceCommCode,dutyModeCode,milCourseCode,milSchoolCode,awardCode,master,civeligibility,lineOfDutyStatus,unitCodeDAO]; Root of BeanFactory hierarchy}>
2005-04-04 22:33:19,570 INFO [org.springframework.orm.hibernate.LocalSessionFactoryBean] - <Closing Hibernate SessionFactory>
2005-04-04 22:33:19,570 INFO [net.sf.hibernate.impl.SessionFactoryImpl] - <closing>


the milcoursecode table only serve as a lookup table for the accreditation table so there is no need to save or update anything on it. the coursecode and ascoursecode could be two different record on milcoursecode table and i definitely need them both. i've found out that including an insert="false" and update="false" to the key-many-to-one is not the solution to make the execution ignore the coursecode and ascoursecode in saving or updating. im really having a hard time on this one because i am just new in using hibernate. i'll appreciate any help, suggestions, advice, etc. please help me .... : (


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 04, 2005 8:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
You should be able to map this if you don't use Key-many-to-one's in the composite key definition. I avoid key-many-to-one as its less flexible (but it can be more convenient). Remember the added object many-to-one mappings need to have update, and insert set to false.


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.