-->
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.  [ 6 posts ] 
Author Message
 Post subject: one-to-many relationship throws NullPointer
PostPosted: Fri Jun 23, 2006 8:43 am 
Beginner
Beginner

Joined: Fri Jun 23, 2006 6:28 am
Posts: 22
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


Top
 Profile  
 
 Post subject: What line is the number 64
PostPosted: Fri Jun 23, 2006 10:08 am 
Regular
Regular

Joined: Wed Feb 22, 2006 11:28 am
Posts: 65
Location: Santiago, Chile
Hello Friend:

after reading your problem... and saw your expcetion trace, I want to ask you, what is the line:

"ReportFieldEditAction.java:64".

Can you tell me, then i can help you.

_________________
If you called Wisdom, please help to all to solve theirs problems.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 24, 2006 4:36 pm 
Beginner
Beginner

Joined: Fri Jun 23, 2006 6:28 am
Posts: 22
Hi

Quote:
after reading your problem... and saw your expcetion trace, I want to ask you, what is the line:

"ReportFieldEditAction.java:64".

Can you tell me, then i can help you.


This Class contains this Code:

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();
      }
    }


When I debugged the code, it throws here:
Code:
session.update(parentTable);


So it is because there is already a tuple with the same fieldname in the database. I think it is rather a mapping problem, because I dont know how to create a mapping for a table with two primary keys.

greets


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 24, 2006 5:04 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-declaration-compositeid

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 7:13 am 
Beginner
Beginner

Joined: Fri Jun 23, 2006 6:28 am
Posts: 22
@scarface

Your hint with the composite-id worked. Thanks.

I made it like this:

Code:
<composite-id>
   <key-property name="fieldName" column="FIELD_NAME"/>
   <key-many-to-one name="reportTable" class="ReportTable" column="REPORT_TABLES_ID"/>
</composite-id>


But so It dont update the "fieldName" attribute:

Code:
update
  REPORT_FIELDS
set
  FIELD_DESC=?,
where
  FIELD_NAME=? and REPORT_TABLES_ID=?


It sets only the property field "fieldDesc". How can I make, that it also updates the propertys from the composite-id?

greets


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 7:29 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
take off

dynamic-update="true"

from the top of of the mapping file you will see all the feilds

not fieldName because that's in the where clause !!

_________________
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.