-->
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.  [ 5 posts ] 
Author Message
 Post subject: UnresolvableObjectException: how to fix problem
PostPosted: Thu May 27, 2004 5:22 am 
Newbie

Joined: Thu May 27, 2004 12:21 am
Posts: 8
Hibernate 2.1.1
Oracle 8.1.6

Here is my snippets.

mapping document:

Code:

<many-to-one
          name="cargo"   
          class="eg.CodeCargo">
   <column name="CARGO"/>
</many-to-one>

    <many-to-one
        name="cargoWaggon"
        class="eg.CargoWaggon"
      >
        <column name="NUM_TRAIN" />
        <column name="WAG_NUM" />
        <column name="DATE_INP" />
    </many-to-one>
...


Everithing works fine, until one of composite-id column is NULL
then UnresolvableObjectException occurs
here is part of stack trace:

Code:
2004-05-27 09:24:36,408 ERROR [STDERR] net.sf.hibernate.UnresolvableObjectException: No row with the given identifier exists: com.azovstal.ugdt.hibernate.CargoWaggonPK@10704e1[numTrain=<null>,numWaggon=108,dateInp=<null>], of class: com.azovstal.ugdt.hibernate.CargoWaggon
   at net.sf.hibernate.UnresolvableObjectException.throwIfNull(UnresolvableObjectException.java:38)
   at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1881)
   at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:68)
   at net.sf.hibernate.type.EntityType.resolveIdentifier(EntityType.java:215)
   at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2132)
   at net.sf.hibernate.loader.Loader.doQuery(Loader.java:239)
   at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132)
   at net.sf.hibernate.loader.Loader.doList(Loader.java:949)
   at net.sf.hibernate.loader.CriteriaLoader.list(CriteriaLoader.java:109)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3440)
   at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:177)



almost the same occurs, if eg.CodeCargo has value which is absent in referenced table

Code:
2004-05-27 09:34:54,006 ERROR [STDERR] net.sf.hibernate.UnresolvableObjectException: No row with the given identifier exists: 117001, of class: com.azovstal.ugdt.hibernate.CodeCargo
   at net.sf.hibernate.UnresolvableObjectException.throwIfNull(UnresolvableObjectException.java:38)
   at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1881)
   at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:68)
   at net.sf.hibernate.type.EntityType.resolveIdentifier(EntityType.java:215)
   at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2132)
   at net.sf.hibernate.loader.Loader.doQuery(Loader.java:239)
   at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132)
   at net.sf.hibernate.loader.Loader.doList(Loader.java:949)
   at net.sf.hibernate.loader.CriteriaLoader.list(CriteriaLoader.java:109)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3440)
   at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:177)



I do understand why its happening, what am I should write to avoid it?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 27, 2004 5:49 am 
Regular
Regular

Joined: Wed May 12, 2004 3:03 am
Posts: 51
Location: France
Hi,

you should show the java files...


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 27, 2004 9:29 am 
Newbie

Joined: Thu May 27, 2004 12:21 am
Posts: 8
_charles_ wrote:
Hi,

you should show the java files...


which ones?
Persistent objects were generated with hbm2java

Code:
      Transaction tx = session.beginTransaction();
      Criteria criteria = session.createCriteria(template.getClass());

      criteria.add(Expression.ge("dateWeight", beginDate));
      criteria.add(Expression.le("dateWeight", endDate));

      criteria.setMaxResults(maxresults);
      retVal = criteria.list();
   
      tx.commit();



Top
 Profile  
 
 Post subject:
PostPosted: Thu May 27, 2004 9:47 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
You have an exception because with your parameter, you don't have result so the List result is null.
Show your mapping files and the java sources with the criteria... not the POJO.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 12:53 am 
Newbie

Joined: Thu May 27, 2004 12:21 am
Posts: 8
subich wrote:
Show your mapping files and the java sources with the criteria... not the POJO.

here is complete mapping files end java sources


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

<hibernate-mapping>

<class
    name="com.azovstal.balanc.hibernate.CargoBalance"
    table="CARGO_BALANCE"
    schema="BALANC"
>

    <id
        name="cargoBalanceId"
        type="java.lang.Integer"
        column="CARGO_BALANCE_ID"
    >
        <generator class="assigned" />
    </id>


    <property
        name="liter"
        type="java.lang.String"
        column="LITER"
        length="3"
    />
    <property
        name="worksComplete"
        type="java.lang.String"
        column="WORKS_COMPLETE"
        length="10"
    />
    <property
        name="dateComplete"
        type="java.sql.Date"
        column="DATE_COMPLETE"
        length="7"
    />
    <property
        name="uzComplete"
        type="java.lang.String"
        column="UZ_COMPLETE"
        length="8"
    />
    <property
        name="dateUzComplete"
        type="java.sql.Date"
        column="DATE_UZ_COMPLETE"
        length="7"
    />
    <property
        name="recipient"
        type="java.math.BigDecimal"
        column="RECIPIENT"
        length="22"
    />
    <property
        name="sender"
        type="java.math.BigDecimal"
        column="SENDER"
        length="22"
    />
      <property name="dateWeight" type="java.util.Date" column="DATE_WEIGHT" length="7"/>
      <property name="weight" type="java.math.BigDecimal" column="WEIGHT" length="8"/>

      <property
        name="weightBal"
        type="java.math.BigDecimal"
        column="WEIGHT_BAL"
        length="8"
    />
    <property
        name="dateTare"
        type="java.sql.Date"
        column="DATE_TARE"
        length="7"
    />
    <property
        name="weightTareBal"
        type="java.math.BigDecimal"
        column="WEIGHT_TARE_BAL"
        length="8"
    />
    <property
        name="weightTare"
        type="java.math.BigDecimal"
        column="WEIGHT_TARE"
        length="8"
    />
    <property
        name="dateDebris"
        type="java.sql.Date"
        column="DATE_DEBRIS"
        length="7"
    />
    <property
        name="tareDebris"
        type="java.math.BigDecimal"
        column="TARE_DEBRIS"
        length="8"
    />
    <property
        name="tareDebrisBal"
        type="java.math.BigDecimal"
        column="TARE_DEBRIS_BAL"
        length="8"
    />
    <property
        name="signError"
        type="java.lang.Boolean"
        column="SIGN_ERROR"
        length="1"
    />
    <property
        name="weightDoc"
        type="java.math.BigDecimal"
        column="WEIGHT_DOC"
        length="8"
    />
    <property
        name="tonnage"
        type="java.math.BigDecimal"
        column="TONNAGE"
        length="8"
    />
    <property
        name="weigher"
        type="java.lang.String"
        column="WEIGHER"
        length="6"
    />
    <property
        name="stationDestin"
        type="java.lang.Integer"
        column="STATION_DESTIN"
        length="6"
    />
    <property
        name="signDeviation"
        type="java.lang.Boolean"
        column="SIGN_DEVIATION"
        length="1"
    />
    <property
        name="tareBrus"
        type="java.math.BigDecimal"
        column="TARE_BRUS"
        length="8"
    />
    <!-- property
        name="numTrain"
        type="java.lang.Short"
        column="NUM_TRAIN"
        length="4"
    / -->
    <!-- property
        name="dateInp"
        type="java.sql.Date"
        column="DATE_INP"
        length="7"
    / -->
    <property
        name="signDelete"
        type="java.lang.Boolean"
        column="SIGN_DELETE"
        length="1"
    />
    <property
        name="stationSender"
        type="java.lang.Integer"
        column="STATION_SENDER"
        length="6"
    />
    <property
        name="signImport"
        type="java.lang.Boolean"
        column="SIGN_IMPORT"
        length="1"
    />
    <property
        name="sirnRasc"
        type="java.lang.Boolean"
        column="SIRN_RASC"
        length="1"
    />
    <property
        name="signEdit"
        type="java.lang.Boolean"
        column="SIGN_EDIT"
        length="1"
    />





    <!-- associations -->
      <many-to-one name="codeOperation" class="com.azovstal.balanc.hibernate.CodeOperation">
         <column name="OPERATION"/>
      </many-to-one>


      <many-to-one name="balance" class="com.azovstal.balanc.hibernate.CodeBalance">
         <column name="BALANCE"/>
      </many-to-one>

      <many-to-one name="worksSender" class="com.azovstal.common.hibernate.CodeWorks">
         <column name="WORKS_SENDER"/>
      </many-to-one>

      <many-to-one name="worksRecipient" class="com.azovstal.common.hibernate.CodeWorks">
         <column name="WORKS_RECIPIENT"/>
      </many-to-one>

      <many-to-one name="cargo" class="com.azovstal.ugdt.hibernate.CodeCargo"
                  outer-join="true"
                  >
         <column name="CARGO"/>
      </many-to-one>



    <!-- uni-directional one-to-one association to WaggonWork -->
    <many-to-one
        name="waggonWork"
        class="com.azovstal.ugdt.hibernate.CargoWaggon"
        not-null="false"
        outer-join="true"
    >
        <column name="NUM_TRAIN" />
        <column name="WAG_NUM" />
        <column name="DATE_INP" />
    </many-to-one>

</class>
</hibernate-mapping>


Code:
<?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>

<class
    name="com.azovstal.ugdt.hibernate.CargoWaggon"
    table="CARGO_WAGGON2"
    schema="UGDT"
>

    <composite-id name="comp_id" class="com.azovstal.ugdt.hibernate.CargoWaggonPK">
        <key-property
            name="numTrain"
            column="NUM_TRAIN"
            type="java.lang.Integer"
            length="10"
        />
        <key-property
            name="numWaggon"
            column="NUM_WAGGON"
            type="java.lang.String"
            length="8"
        />
        <key-property
            name="dateInp"
            column="DATE_INP"
            type="java.util.Date"
            length="10"
        />
    </composite-id>

<property column="NUM_INVOICE_IN" length="10" name="numInvoiceIn" not-null="true" type="java.lang.String"/>
<property column="CARGO_IN" length="10" name="cargoIn" type="java.lang.Long"/>
<property column="WEIGHT_CARGO_IN" length="7" name="weightCargoIn" type="java.lang.Float"/>
<property column="OWNER_CARGO_IN" length="10" name="ownerCargoIn" type="java.lang.Long"/>
<property column="SENDER_IN" length="10" name="senderIn" type="java.lang.Long"/>
<property column="CODE_PAYER_IN" length="10" name="codePayerIn" type="java.lang.Long"/>
<property column="SIGN_IMPORT" length="1" name="signImport" type="java.lang.Byte"/>
<property column="METHOD_WEIGHT" length="2" name="methodWeight" type="java.lang.Short"/>
<property column="NUM_PASPORT" length="6" name="numPasport" type="java.lang.String"/>
<property column="NUM_SERTIF" length="8" name="numSertif" type="java.lang.String"/>
<property column="TARIF_DIST_IN" length="8" name="tarifDistIn" type="java.lang.Integer"/>
<property column="TARIF_SCHEMA_IN" length="3" name="tarifSchemaIn" type="java.lang.Short"/>
<property column="TARIF_IN" length="8" name="tarifIn" type="java.lang.Float"/>
<property column="TARIF_IN_CALC" length="8" name="tarifInCalc" type="java.lang.Float"/>
<property column="REWEIGHT_IN" length="6" name="reweightIn" type="java.lang.Float"/>
<property column="STATION_MPS_IN" length="8" name="stationMpsIn" type="java.lang.Integer"/>
<property column="STATION_WORKS_IN" length="2" name="stationWorksIn" type="java.lang.Short"/>
<property column="WORKS_IN" length="3" name="worksIn" type="java.lang.Short"/>
<property column="FRONT_IN" length="3" name="frontIn" type="java.lang.Short"/>
<property column="NUM_INVOICE_WORKS" length="8" name="numInvoiceWorks" type="java.lang.Integer"/>
<property column="SIGN_GIVEN" length="1" name="signGiven" type="java.lang.Byte"/>
<property column="SIGN_TICKET_IN" length="15" name="signTicketIn" type="java.lang.Long"/>
<property column="DATE_UPD" length="7" name="dateUpd" not-null="true" type="java.util.Date"/>
<property column="NUM_PLACE_IN" length="5" name="numPlaceIn" type="java.lang.Integer"/>
<property column="DATE_TICKET_IN" length="7" name="dateTicketIn" type="java.util.Date"/>




    <!-- associations -->
    <!-- bi-directional one-to-many association to CargoBalance -->
    <set
        name="cargoBalances"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="NUM_TRAIN" />
            <column name="NUM_WAGGON" />
            <column name="DATE_INP" />
        </key>
        <one-to-many
            class="com.azovstal.balanc.hibernate.CargoBalance"
        />
    </set>



</class>
</hibernate-mapping>



Java source


Code:

  public List getByTemplate(Date beginDate, Date endDate, Object template,
                            int maxresults) {
    List retVal = null;

    System.out.println("beginDate "+beginDate);
    System.out.println("endDate "+endDate);

    try {
      InitialContext inictx = new InitialContext();
      sessionFactory = (SessionFactory) inictx.lookup(
          "java:/hibernate/BalancFactory");
    }
    catch (NamingException ex) {
      ex.printStackTrace();
    }

    try {
      BeanInfo info = Introspector.getBeanInfo(template.getClass(),
                                               template.getClass().
                                               getSuperclass());

      PropertyDescriptor[] pd = info.getPropertyDescriptors();

      Session session = sessionFactory.openSession();
      Transaction tx = session.beginTransaction();
      Criteria criteria = session.createCriteria(template.getClass());

      Map propertyValues = new HashMap();

      for (int i = 0; i < pd.length; i++) {
        Method getMethod = pd[i].getReadMethod();
        String name = pd[i].getName();
        Object propertyValue = getMethod.invoke(template, new Object[0]);

        if (propertyValue != null && !name.equals("dateWeight") &&!name.equals("wagNum")){
          propertyValues.put(name, propertyValue);
          System.out.println("Not date criteria added "+ name +" value "+propertyValue);

        }
      }

      criteria.add(Expression.allEq(propertyValues));
      criteria.add(Expression.ge("dateWeight", beginDate));
      criteria.add(Expression.le("dateWeight", endDate));



      criteria.setMaxResults(maxresults);
      //criteria.addOrder(Order.desc("dateWeight"));

      retVal = criteria.list();
      System.out.println("ResultSetCount"+retVal.size());

      tx.commit();
      session.close();

    }
    catch (InvocationTargetException ex) {
      System.out.println("[ERROR] [BALANCE]" + ex.getMessage());
    }
    catch (IllegalArgumentException ex) {
      System.out.println("[ERROR] [BALANCE]" + ex.getMessage());
    }
    catch (IllegalAccessException ex) {
      System.out.println("[ERROR] [BALANCE]" + ex.getMessage());
    }
    catch (HibernateException ex) {
      System.out.println("[ERROR] [BALANCE]" + ex.getMessage());
      ex.printStackTrace();
    }

    catch (IntrospectionException ex) {
      System.out.println("[ERROR] [BALANCE]" + ex.getMessage());
    }

    return retVal;
  }


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