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.  [ 2 posts ] 
Author Message
 Post subject: Prob - UserType and objects having an association to itself
PostPosted: Wed Apr 02, 2008 4:29 am 
Newbie

Joined: Mon May 30, 2005 5:42 pm
Posts: 2
Hello!

First the facts:

Hibernate version: 3.2.6.ga

Mapping documents:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
    <class
        name="itcjb.bellerophon2.business.domain.balance.BalanceCategoryValue"
        table="balancecategoryvalue"
    >

        <id
            name="id"
            column="IDbalanceCategoryValue"
            type="long"
            unsaved-value="0"
        >
            <generator class="identity">
              <!-- 
                  To add non XDoclet generator parameters, create a file named
                  hibernate-generator-params-BalanceCategoryValue.xml
                  containing the additional parameters and place it in your merge dir.
              -->
            </generator>
        </id>

        <many-to-one
            name="balanceCategory"
            class="itcjb.bellerophon2.business.domain.balance.BalanceCategory"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="balanceCategoryID"
            not-null="true"
        />

        <many-to-one
            name="balanceValue"
            class="itcjb.bellerophon2.business.domain.balance.BalanceValue"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="balanceValueID"
            not-null="false"
        />

        <many-to-one
            name="parentBalanceCategoryValue"
            class="itcjb.bellerophon2.business.domain.balance.BalanceCategoryValue"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="parentBalanceCategoryValueID"
            not-null="false"
        />

        <bag
            name="listOfChildBalanceCategoryValues"
            lazy="false"
            inverse="true"
            cascade="save-update"
        >

            <key
                column="parentBalanceCategoryValueID"
            >
            </key>

            <one-to-many
                  class="itcjb.bellerophon2.business.domain.balance.BalanceCategoryValue"
            />

      </bag>

        <bag
            name="listOfSablItems"
            lazy="false"
            inverse="true"
            cascade="all-delete-orphan"
        >

            <key
                column="balanceCategoryValueID"
            >
            </key>

            <one-to-many
                  class="itcjb.bellerophon2.business.domain.financialYear.SaBLItem"
            />

      </bag>

        <property
            name="amount"
            type="itcjb.bellerophon2.business.domain.amount.AmountUserType"
            update="true"
            insert="true"
            column="amount"
        />

        <property
            name="lastModified"
            type="java.util.GregorianCalendar"
            update="true"
            insert="true"
            column="lastModified"
        />

        <many-to-one
            name="modifier"
            class="itcjb.bellerophon2.business.domain.user.User"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="modifierID"
            not-null="true"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-BalanceCategoryValue.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>


Name and version of the database you are using: MySQL 5.0

The generated SQL (show_sql=true):
Code:
select listofchil0_.parentBalanceCategoryValueID as parentBa4_1_, listofchil0_.IDbalanceCategoryValue as IDbalanc1_1_, listofchil0_.IDbalanceCategoryValue as IDbalanc1_54_0_, listofchil0_.balanceCategoryID as balanceC2_54_0_, listofchil0_.balanceValueID as balanceV3_54_0_, listofchil0_.parentBalanceCategoryValueID as parentBa4_54_0_, listofchil0_.amount as amount54_0_, listofchil0_.lastModified as lastModi6_54_0_, listofchil0_.modifierID as modifierID54_0_ from balancecategoryvalue listofchil0_ where listofchil0_.parentBalanceCategoryValueID=?


Problem: If I try to get an amount (is a UserType (works perfectly in other classes)), of a Category that has no parent, I get null. But if i execute the sql statement manually at the database. I get the correct values.
I tested a little bit and set the parentBalanceCategoryValueID to something else, I get the correct value.

Can anyone help me? - I really don't know where my mistake is!

Thank you
Joerg Bergner


Top
 Profile  
 
 Post subject: Got it!
PostPosted: Wed Apr 09, 2008 8:18 am 
Newbie

Joined: Mon May 30, 2005 5:42 pm
Posts: 2
Hi!

I found a solution in following thread: http://forum.hibernate.org/viewtopic.ph ... et+wasnull

Thank you!

Joerg Bergner


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