Announcement Announcement Module
Collapse
No announcement yet.
many-to-one not-found attribute not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • many-to-one not-found attribute not working

    Hello,

    I'm using Hibernate 3.2.1.ga with Spring 1.2.8.

    I'm calling the getHibernateTemplate.save() method trying to insert an object. I have the following many-to-one mapping entry that associates a lookup table to non lookup table. When I set up my stateDistrictLookup object I purposely set an invalid STATE_DISTRICT_CODE hoping to get a foreign key not found exception. However the record still gets inserted without any error. A null is inserted for the bogus STATE_DISTRICT_CODE.
    I have explicitly set the not-found attribute to exception - but it has no affect.

    Any thoughts on this?

    Code:
    <many-to-one name="stateDistrictLookup" class="StateDistrictLookup" insert="false" update="false" not-found="exception"> 
    <column name="STATE_DISTRICT_CODE" length="2"/> 
    </many-to-one>

  • #2
    If you've set insert="false" then doesn't it make sense that a value isn't inserted? I would have thought this would mean a null was inserted instead.

    Comment


    • #3
      Hi - thanks for the reply -

      I removed the insert="false" and it has the same behavior -- inserting a null into the state_district_code instead of throwing a parent key not found exception.

      Any other suggestions?

      Code:
              <many-to-one name="stateDistrictLookup" class="StateDistrictLookup"  update="false" not-found="exception">
                  <column name="STATE_DISTRICT_CODE" length="2"/>
              </many-to-one>

      Comment


      • #4
        Hmmm, this sounds like it's completely ignoring the mapping. Have to have a think. As for the null, I would have thought adding not-null="true" would prevent the null inserts.
        http://www.hibernate.org/hib_docs/v3...irectional-m21

        Is it possible to write a TestCase for this and post this along with the code that isn't working?

        Comment


        • #5
          No luck.

          <many-to-one name="stateDistrictLookup" class="StateDistrictLookup" not-null="true" update="false">
          <column name="STATE_DISTRICT_CODE" length="2"/>
          </many-to-one>

          row still gets inserted with out any exception.

          Here is the sql that Hibernate is generating:
          Code:
          Hibernate: 
              /* get current state com.west.mds.caselaw.TcProviderLookup */ select
                  tcprovider_.TC_PROVIDER_CODE,
                  tcprovider_.TC_PROVIDER_NAME as TC2_18_ 
              from
                  MACHV.TC_PROVIDER_LOOKUP tcprovider_ 
              where
                  tcprovider_.TC_PROVIDER_CODE=?
          Hibernate: 
              /* get current state com.west.mds.caselaw.StateDistrictLookup */ select
                  statedistr_.STATE_DISTRICT_CODE,
                  statedistr_.STATE_DISTRICT_DESC as STATE2_20_ 
              from
                  MACHV.STATE_DISTRICT_LOOKUP statedistr_ 
              where
                  statedistr_.STATE_DISTRICT_CODE=?
          Hibernate: 
              /* get current state com.west.mds.caselaw.SuitNatureLookup */ select
                  suitnature_.SUIT_NATURE_CODE,
                  suitnature_.SUIT_NATURE_DESC as SUIT2_32_ 
              from
                  MACHV.SUIT_NATURE_LOOKUP suitnature_ 
              where
                  suitnature_.SUIT_NATURE_CODE=?
          Hibernate: 
              /* get current state com.west.mds.caselaw.DateTypeLookup */ select
                  datetypelo_.DATE_TYPE_CODE,
                  datetypelo_.DATE_TYPE_TEXT as DATE2_31_ 
              from
                  MACHV.DATE_TYPE_LOOKUP datetypelo_ 
              where
                  datetypelo_.DATE_TYPE_CODE=?
          Hibernate: 
              /* get current state com.west.mds.caselaw.CountyLookup */ select
                  countylook_.COUNTY_CODE,
                  countylook_.STATE_DISTRICT_CODE as STATE2_19_,
                  countylook_.US_DISTRICT_COURT_CODE as US3_19_,
                  countylook_.COUNTY as COUNTY19_,
                  countylook_.COUNTY_TERM as COUNTY5_19_,
                  countylook_.COUNTY_TERM_CODE as COUNTY6_19_,
                  countylook_.DISTRICT as DISTRICT19_,
                  countylook_.DIVISION as DIVISION19_,
                  countylook_.APPELLATE_COURT as APPELLATE9_19_ 
              from
                  MACHV.COUNTY_LOOKUP countylook_ 
              where
                  countylook_.COUNTY_CODE=?
          Hibernate: 
              /* get current state com.west.mds.caselaw.TcLabelLookup */ select
                  tclabelloo_.TC_LABEL_CODE,
                  tclabelloo_.TC_HEADING_CODE as TC2_15_,
                  tclabelloo_.TC_LABEL as TC3_15_,
                  tclabelloo_.TC_LABEL_SORT_NUMBER as TC4_15_ 
              from
                  MACHV.TC_LABEL_LOOKUP tclabelloo_ 
              where
                  tclabelloo_.TC_LABEL_CODE=?
          Hibernate: 
              /* get current state com.west.mds.caselaw.MemTabLookup */ select
                  memtablook_.MEM_TAB_CODE,
                  memtablook_.MEM_TAB_DESC as MEM2_14_ 
              from
                  MACHV.MEM_TAB_LOOKUP memtablook_ 
              where
                  memtablook_.MEM_TAB_CODE=?
          Hibernate: 
              /* insert com.west.mds.caselaw.DocumentFamily
                  */ insert 
                  into
                      MACHV.CASE
                      (TC_PROVIDER_CODE, STATE_DISTRICT_CODE, SUIT_NATURE_CODE, FILED_DATE_TYPE_CODE, DOC_KIND_CODE, COUNTY_CODE, TC_LABEL_CODE, MEM_TAB_CODE, SERIAL_NUMBER, ELECTRONIC_ID, FILED_DATE, RECORD_STATUS, APPENDIX_FLAG, BLOCKED_FLAG, SERIAL_CENTURY, REPLACING_SERIAL_NUMBER, ON_WESTLAW_FLAG, KEY_CITE_COLOR_CODE, INSTACITE_SUPPRESS_FLAG, ON_NORM_FLAG, TC_DOC_FLAG, FULL_TEXT_CODE, CREATE_USER, CREATE_DATE, MODIFY_USER, MODIFY_DATE, PATENT_APPLICATION_DATE, DMS_PUB_ID, CLIP_DATE, JUDGE, CLERK, PATENT_INVENTOR, PATENT_ASSIGNEE, NOTES, CONTEXT, LEGACY_ID, TC_DOC_HEADING, ADJUSTED_CITE_WORKFLOW_DATE, CASE_ABSTRACT_FLAG, CAUSE, CASE_UUID) 
                  values
                      (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
          I've highlighted the fetch for the state_district_lookup. Any idea why these pre-fetches are occurring? Is there a way to not have them executed?

          Comment


          • #6
            Thought I'd provide a bit more info.

            Here is my POJO:
            Code:
            public class DocumentFamily
            {
                	// Fields
            	private String caseUuid;
            	private TcProviderLookup tcProviderLookup;
            	private DocumentKindLookup documentKindLookup;
            	private DateTypeLookup dateTypeLookup;
            	private SuitNatureLookup suitNatureLookup;
            	private StateDistrictLookup stateDistrictLookup;
            	private CountyLookup countyLookup;
            	private TcLabelLookup tcLabelLookup;
            
            	private String appendixFlag;
            	private String blockedFlag;
            	private String onWestlawFlag;
            	private String onNormFlag;
            	private String tcDocFlag;
            	private String caseAbstractFlag;
            
                public DocumentFamily()
                {
                }
                 // full constructor omitted do to size limitations.
            
                   public String getCaseUuid()
                {
                    return caseUuid;
                }
            
                public void setCaseUuid(String caseUuid)
                {
                    this.caseUuid = caseUuid;
                }
            
                public TcProviderLookup getTcProviderLookup()
                {
                    return tcProviderLookup;
                }
            
                public void setTcProviderLookup(TcProviderLookup tcProviderLookup)
                {
                    this.tcProviderLookup = tcProviderLookup;
                }
            
                public DocumentKindLookup getDocumentKindLookup()
                {
                    return documentKindLookup;
                }
            
                public void setDocumentKindLookup(DocumentKindLookup documentKindLookup)
                {
                    this.documentKindLookup = documentKindLookup;
                }
            
                public DateTypeLookup getDateTypeLookup()
                {
                    return dateTypeLookup;
                }
            
                public void setDateTypeLookup(DateTypeLookup dateTypeLookup)
                {
                    this.dateTypeLookup = dateTypeLookup;
                }
            
                public SuitNatureLookup getSuitNatureLookup()
                {
                    return suitNatureLookup;
                }
            
                public void setSuitNatureLookup(SuitNatureLookup suitNatureLookup)
                {
                    this.suitNatureLookup = suitNatureLookup;
                }
            
                public StateDistrictLookup getStateDistrictLookup()
                {
                    return stateDistrictLookup;
                }
            
                public void setStateDistrictLookup(StateDistrictLookup stateDistrictLookup)
                {
                    this.stateDistrictLookup = stateDistrictLookup;
                }
            
                public CountyLookup getCountyLookup()
                {
                    return countyLookup;
                }
            
                public void setCountyLookup(CountyLookup countyLookup)
                {
                    this.countyLookup = countyLookup;
                }
            
                public String getMemTabCode()
                {
                    return memTabCode;
                }
            
                public void setMemTabCode(String memTabCode)
                {
                    this.memTabCode = memTabCode;
                }
            
                public TcLabelLookup getTcLabelLookup()
                {
                    return tcLabelLookup;
                }
            
                public void setTcLabelLookup(TcLabelLookup tcLabelLookup)
                {
                    this.tcLabelLookup = tcLabelLookup;
                }
            
                public String getAppendixFlag()
                {
                    return appendixFlag;
                }
            
                public void setAppendixFlag(String appendixFlag)
                {
                    this.appendixFlag = appendixFlag;
                }
            
                public String getBlockedFlag()
                {
                    return blockedFlag;
                }
            
                public void setBlockedFlag(String blockedFlag)
                {
                    this.blockedFlag = blockedFlag;
                }
            
                public String getOnWestlawFlag()
                {
                    return onWestlawFlag;
                }
            
                public void setOnWestlawFlag(String onWestlawFlag)
                {
                    this.onWestlawFlag = onWestlawFlag;
                }
            
                public String getOnNormFlag()
                {
                    return onNormFlag;
                }
            
                public void setOnNormFlag(String onNormFlag)
                {
                    this.onNormFlag = onNormFlag;
                }
            
                public String getTcDocFlag()
                {
                    return tcDocFlag;
                }
            
                public void setTcDocFlag(String tcDocFlag)
                {
                    this.tcDocFlag = tcDocFlag;
                }
            
                public String getCaseAbstractFlag()
                {
                    return caseAbstractFlag;
                }
            
                public void setCaseAbstractFlag(String caseAbstractFlag)
                {
                    this.caseAbstractFlag = caseAbstractFlag;
                }
            }

            Here is mapping file:
            Code:
            <?xml version="1.0"?>
            <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
            "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
            <!-- Generated Jan 24, 2007 2:14:44 PM by Hibernate Tools 3.2.0.beta8 -->
            <hibernate-mapping package="com.west.mds.caselaw">
                <class name="DocumentFamily" table="CASE">
                    <id name="caseUuid" type="string">
                        <column name="CASE_UUID" length="33"/>
                        <generator class="assigned"/>
                    </id>
                    <many-to-one name="tcProviderLookup" class="TcProviderLookup" fetch="select">
                        <column name="TC_PROVIDER_CODE" precision="10" scale="0" not-null="true"/>
                    </many-to-one>
                    <many-to-one name="stateDistrictLookup" class="StateDistrictLookup" not-null="true"  update="false">
                        <column name="STATE_DISTRICT_CODE" length="2"/>
                    </many-to-one>
                    <many-to-one name="suitNatureLookup" class="SuitNatureLookup" fetch="select">
                        <column name="SUIT_NATURE_CODE" precision="10" scale="0"/>
                    </many-to-one>
                    <many-to-one name="dateTypeLookup" class="DateTypeLookup" fetch="select">
                        <column name="FILED_DATE_TYPE_CODE" precision="3" scale="0"/>
                    </many-to-one>
                    <many-to-one name="documentKindLookup" class="DocumentKindLookup" fetch="select">
                        <column name="DOC_KIND_CODE" precision="10" scale="0"/>
                    </many-to-one>
                    <many-to-one name="countyLookup" class="CountyLookup" fetch="select">
                        <column name="COUNTY_CODE" precision="10" scale="0"/>
                    </many-to-one>
                    <many-to-one name="tcLabelLookup" class="TcLabelLookup" fetch="select">
                        <column name="TC_LABEL_CODE" precision="10" scale="0"/>
                    </many-to-one>
                    <many-to-one name="memTabLookup" class="MemTabLookup" fetch="select">
                        <column name="MEM_TAB_CODE" length="1"/>
                    </many-to-one>
                    <property name="appendixFlag" type="string">
                        <column name="APPENDIX_FLAG" length="1" not-null="true"/>
                    </property>
                    <property name="blockedFlag" type="string">
                        <column name="BLOCKED_FLAG" length="1" not-null="true"/>
                    </property>
                    <property name="onWestlawFlag" type="string">
                        <column name="ON_WESTLAW_FLAG" length="1" not-null="true"/>
                    </property>
                    <property name="onNormFlag" type="string">
                        <column name="ON_NORM_FLAG" length="1" not-null="true"/>
                    </property>
                    <property name="tcDocFlag" type="string">
                        <column name="TC_DOC_FLAG" length="1" not-null="true"/>
                    </property>
                    <property name="caseAbstractFlag" type="string">
                        <column name="CASE_ABSTRACT_FLAG" length="1" not-null="true"/>
                    </property>
                </class>
            </hibernate-mapping>
            How I'm using the objects in my code:

            Code:
                    
                        DocumentFamily documentFamily = new DocumentFamily();
                        // set properties
                        documentFamily.setAppendixFlag(buffer.toString());
                        documentFamily.setBlockedFlag(buffer.toString());       
                         ....
              
                        // set many-to-one associations
                        TcProviderLookup tcProviderLookup = new TcProviderLookup();
                        tcProviderLookup.setTcProviderCode(new Long(buffer.toString()));
                        documentFamily.setTcProviderLookup(tcProviderLookup);
            
                        StateDistrictLookup stateDistrictLookup = new StateDistrictLookup();
                        stateDistrictLookup.setStateDistrictCode(buffer.toString());
                        documentFamily.setStateDistrictLookup(stateDistrictLookup);
            
                        DateTypeLookup dateTypeLookup = new DateTypeLookup();
                        dateTypeLookup.setDateTypeCode(new Integer(buffer.toString()));
                        documentFamily.setDateTypeLookup(dateTypeLookup);
            
                        CountyLookup countyLookup = new CountyLookup();
                        countyLookup.setCountyCode(new Long(buffer.toString()));
                        documentFamily.setCountyLookup(countyLookup);
            
                        MemTabLookup memTabLookup = new MemTabLookup();
                        memTabLookup.setMemTabCode(buffer.toString());
                        documentFamily.setMemTabLookup(memTabLookup);
            
                        TcLabelLookup tcLabel = new TcLabelLookup();
                        tcLabel.setTcLabelCode(new Long(buffer.toString()));
                        documentFamily.setTcLabelLookup(tcLabel);
            
                        SuitNatureLookup suitNatureLookup = new SuitNatureLookup();
                        suitNatureLookup.setSuitNatureCode(new Long(buffer.toString()));
                        documentFamily.setSuitNatureLookup(suitNatureLookup);
            
                            // make call to machv insert service
                            ApplicationContext context = new ClassPathXmlApplicationContext("/xml/machv.context.xml");
                            MachvService service = (MachvService) context.getBean("machvService");
                             
                            // uses a dao object to call getHibernateTemplate.save()
                            service.insert(documentFamily);
            In my test I set a value on the StateDistrictLookup that does not exist in the lookup table - hoping to get a parent key not found exception...

            Please let me know if additional information would be useful.

            thanks,
            Tom

            Comment


            • #7
              Do all your other many-to-one mappings work? Is it only this one that fails? Have you tried the same thing with any of the others?

              Comment


              • #8
                They all behave the same. When a value that does not exist in the lookup table is set on its respective object - a parent key not found exception is not thrown and a null value is inserted into the non lookup table.

                Comment


                • #9
                  Also - if for example, instead of a many-to-one association the stateDistrict is mapped as a property --> so it would be a String on the DocumentFamily object instead of a StateDistrictLookup object. I do not see the pre-fetch and a parent key not found exception is thrown.

                  Comment


                  • #10
                    I guess it would also be useful to see the mapping file for one of the may-to-one associations that isn't working as well.
                    e.g.
                    http://www.hibernate.org/hib_docs/v3...irectional-m21

                    Comment


                    • #11
                      Is this what your requesting?

                      Code:
                      <?xml version="1.0"?>
                      <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                      "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
                      <!-- Generated Jan 24, 2007 2:14:44 PM by Hibernate Tools 3.2.0.beta8 -->
                      <hibernate-mapping package="com.west.mds.caselaw">
                          <class name="StateDistrictLookup" table="STATE_DISTRICT_LOOKUP">
                              <id name="stateDistrictCode" type="string">
                                  <column name="STATE_DISTRICT_CODE" length="2" />
                                  <generator class="assigned" />
                              </id>
                              <property name="stateDistrictDesc" type="string">
                                  <column name="STATE_DISTRICT_DESC" length="80" />
                              </property>
                          </class>
                      </hibernate-mapping>

                      Comment

                      Working...
                      X