Hi
I have a table "ReportTables" which containst several "ReportFields". "ReportFields" is also a table, which contains two primary keys: a pk called "FIELD_NAME" and one called "REPORT_TABLES_ID". Both together gives a unique tuple.
The hibernate mapping looks like this:
Table ReportField:
Code:
<hibernate-mapping package="gugus">
<class name="ReportField" table="REPORT_FIELDS" dynamic-update="true" dynamic-insert="true">
<id name="fieldName" column="FIELD_NAME">
<generator class="assigned"/>
</id>
<property name="fieldDesc" column="FIELD_DESC"/>
<many-to-one name="reportTable" class="ReportTable" column="REPORT_TABLES_ID"/>
</class>
</hibernate-mapping>
Mapping for ReportTable:
Code:
<hibernate-mapping package="gugus">
<class name="ReportTable" table="REPORT_TABLES" dynamic-update="true" dynamic-insert="true">
<id name="id" type="long" column="REPORT_TABLES_ID">
<generator class="assigned"/>
</id>
<property name="tableName" column="TABLE_NAME"/>
<set name="reportFields" table="REPORT_FIELDS" cascade="all" inverse="true">
<key column="REPORT_TABLES_ID"/>
<one-to-many class="ReportField"/>
</set>
</class>
</hibernate-mapping>
But now, when I change a ReportField, I recieve a NullPointerException:
Code:
java.lang.NullPointerException
at weblogic.jdbc.wrapper.Statement.cancel(Statement.java:426)
at net.sf.hibernate.impl.BatcherImpl.cancelLastQuery(BatcherImpl.java:279)
at net.sf.hibernate.impl.SessionImpl.cancelQuery(SessionImpl.java:3772)
at gugus.ReportFieldEditAction.doExecute(ReportFieldEditAction.java:64)
at gugus.WebAction.execute(WebAction.java:114)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at gugus.TilesRequestProcessor.process(TilesRequestProcessor.java:193)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
at gugus.hibernate.filter.HibernateFilter.doFilter(HibernateFilter.java:54)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6726)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3766)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2644)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
I think, this is because when I only edit a ReportField (as an example, when I change only the "fieldDesc"), then it finds already one in the database.
This is, how I handle the update of my Object:
Code:
enableTransactionSupport();
Session session = getHibernateSession();
ReportField editReportField = new ReportField();
ReportTable parentTable = null;
try {
ServerAdminSessionObjects sObjects = (ServerAdminSessionObjects)
params.getSessionAttribute(Constants.SESSIONOBJECTS);
editReportField = sObjects.getReportFieldToEdit();
String fieldName = editReportField.getFieldName();
parentTable = editReportField.getReportTable();
WebForm webForm = (WebForm) params.getWebForm();
webForm.updateBean(editReportField);
Criteria searchCrit = session.createCriteria(ReportField.class);
List list = searchCrit.add(Expression.like(FIELD_NAME, editReportField.getFieldName())).list();
if ((list.size() > 0) && (fieldName.equals(((ReportField) list.get(0)).getFieldName()))) {
ActionErrors retVal = new ActionErrors();
retVal.add(FIELD_NAME, new ActionMessage("error.reportfield.edit"));
this.setActionForward(params, params.findForward(ACTION_EDIT_FIELD));
}
parentTable.updateReportField(editReportField);
}
finally {
try {
if (parentTable != null) {
session.update(parentTable);
}
}
catch (HibernateException e) {
session.cancelQuery();
e.printStackTrace();
}
}
How can I solve this problem?
Thanks in advance and greets