Trying to finish an application my predecessor began so I'm not entirely clear on some of my own code here sadly. It all seems to work fine for iinserting but updating isnt working (even when I havent made any changes to the object)
Hibernate version:
hibernate-3.0.5
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="edu.asu.SFAO.DAOs.Scholarship" table="scholarship">
<meta attribute="class-description">
A representation of an ASU scholarship
</meta>
<id name="id" column="scholarshipID" unsaved-value="0" >
<meta attribute="scope-set">protected</meta>
<generator class="native"> </generator>
</id>
<property name="name" type="string" not-null="true" column="name"> </property>
<property name="amountType" type="int" not-null="true" column="amount_type"> </property>
<property name="amount" type="int" not-null="true" column="amount"> </property>
<property name="activationDate" type="string" not-null="true" column="activation_date"> </property>
<property name="deadlineDate" type="string" not-null="true" column="deadline_date"> </property>
<property name="openDeadline" type="int" not-null="true" column="open_deadline"> </property>
<property name="applicationUrl" type="string" not-null="true" column="application_url"> </property>
<property name="needBased" type="int" not-null="true" column="need_based"> </property>
<property name="globalList" type="int" not-null="true" column="global_list"> </property>
<property name="minimumGpa" type="int" not-null="true" column="minimum_gpa"> </property>
<property name="minimumHours" type="int" not-null="true" column="minimum_hours"> </property>
<property name="azResident" type="int" not-null="true" column="az_resident"> </property>
<property name="condition" type="string" not-null="true" column="condition"> </property>
<property name="eligibility" type="string" not-null="true" column="eligibility"> </property>
<property name="description" type="string" not-null="true" column="description"> </property>
<property name="comment" type="string" not-null="true" column="comment"> </property>
<property name="contactName" type="string" not-null="true" column="contact_name"> </property>
<property name="contactOrganization" type="string" not-null="true" column="contact_organization"> </property>
<property name="contactPhone" type="string" not-null="true" column="contact_phone"> </property>
<set name="campuses" table="scholarshipXcampus" inverse="false" cascade="all">
<meta attribute="field-description">
A scholarship can have many campuses associated with it
</meta>
<key column="scholarshipID" />
<many-to-many class="edu.asu.SFAO.DAOs.Campus" column="campusID" />
</set>
<set name="classstandings" table="scholarshipXclassstanding" inverse="false" cascade="all">
<meta attribute="field-description">
A scholarship can have many classstandings associated with it
</meta>
<key column="scholarshipID" />
<many-to-many class="edu.asu.SFAO.DAOs.ClassStanding" column="classstandingID" />
</set>
<set name="donorPrefs" table="scholarshipXdonorpref" inverse="false" cascade="all">
<meta attribute="field-description">
A scholarship can have many donor preferences associated with it
</meta>
<key column="scholarshipID" />
<many-to-many class="edu.asu.SFAO.DAOs.DonorPref" column="donorprefID" />
</set>
<set name="majors" table="scholarshipXmajor" inverse="false" cascade="all">
<meta attribute="field-description">
A scholarship can have many majors associated with it
</meta>
<key column="scholarshipID" />
<one-to-many class="edu.asu.SFAO.DAOs.ScholarshipxMajor" />
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
try
{
hibScholarshipSearchSession = sessionFactory1.openSession();
tx = hibScholarshipSearchSession.beginTransaction();
hibScholarshipSearchSession.saveOrUpdate(scholarship);
tx.commit();
}
.....
Full stack trace of any exception that occurs:
10:57:05,381 ERROR AbstractFlushingEventListener:277 - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not delete collection: [edu.asu.SFAO.DAOs.Scholarship.majors#27]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:63)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:860)
at org.hibernate.action.CollectionRemoveAction.execute(CollectionRemoveAction.java:22)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:138)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at edu.asu.SFAO.Actions.UpdateScholarshipAction.execute(UpdateScholarshipAction.java:58)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at edu.asu.SFAO.Actions.HibernateActionServlet.doPost(HibernateActionServlet.java:199)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:307)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:748)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:678)
at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:871)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.sql.SQLException: Cannot insert the value NULL into column 'scholarshipID', table 'SFAO.dbo.scholarshipXmajor'; column d
oes not allow nulls. UPDATE fails. at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:364)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2754)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2195)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:620)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:483)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:445)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:402)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at org.hibernate.persister.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:850)
... 32 more
Name and version of the database you are using:
ms sql (not sure can investigate further if truly needed)
The generated SQL (show_sql=true):
10:57:05,319 DEBUG SQL:324 - insert into scholarshipXmajor (scholarshipID, majorCode) values (?, ?)
10:57:05,322 DEBUG SQL:324 - update scholarship set name=?, amount_type=?, amount=?, activation_date=?, deadline_date=?, open_deadline=?
, application_url=?, need_based=?, global_list=?, minimum_gpa=?, minimum_hours=?, az_resident=?, condition=?, eligibility=?, description
=?, comment=?, contact_name=?, contact_organization=?, contact_phone=? where scholarshipID=?
10:57:05,336 DEBUG SQL:324 - update campus set name=?, ordering=? where campusID=?
10:57:05,339 DEBUG SQL:324 - update classstanding set name=?, ordering=? where classstandingID=?
10:57:05,342 DEBUG SQL:324 - update donorpref set name=?, ordering=? where donorprefID=?
10:57:05,345 DEBUG SQL:324 - delete from scholarshipXcampus where scholarshipID=?
10:57:05,352 DEBUG SQL:324 - delete from scholarshipXclassstanding where scholarshipID=?
10:57:05,359 DEBUG SQL:324 - delete from scholarshipXdonorpref where scholarshipID=?
10:57:05,365 DEBUG SQL:324 - update scholarshipXmajor set scholarshipID=null where scholarshipID=?
Debug level Hibernate log excerpt:
10:57:05,373 WARN JDBCExceptionReporter:71 - SQL Error: 515, SQLState: 23000
10:57:05,374 ERROR JDBCExceptionReporter:72 - Cannot insert the value NULL into column 'scholarshipID', table 'SFAO.dbo.scholarshipXmajo
r'; column does not allow nulls. UPDATE fails.
10:57:05,381 ERROR AbstractFlushingEventListener:277 - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not delete collection: [edu.asu.SFAO.DAOs.Scholarship.majors#27]
|