Dear members,
I get a LazyInitializationException, executing a simple query like this:
select c from Country as c
where I have defined the Country table like this:
Quote:
CREATE TABLE country (
       country_id VARCHAR(3) NOT NULL
     , name VARCHAR(40) NOT NULL
     , PRIMARY KEY (country_id)
);
and the table shareholder as a foreing key to Country, like this:
Quote:
CREATE TABLE shareholder (
       shareholder_id INT(11) UNSIGNED NOT NULL IDENTITY PRIMARY KEY
     , NIF VARCHAR(10)
     , name VARCHAR(80) NOT NULL
     , last_name VARCHAR(40)
     , type INT(2) UNSIGNED NOT NULL
     , citizenship VARCHAR(3)
     , is_resident BOOL
     , is_credit_entity BOOL
     , CONSTRAINT fk_shareholder_1 FOREIGN KEY (citizenship)
                  REFERENCES country (country_id)
     , CONSTRAINT fk_shareholder_2 FOREIGN KEY (type)
                  REFERENCES shareholder_type (shareholder_type_id)
);
The hbm mapping files are:
Quote:
<hibernate-mapping>
    <class name="com.schinvest.lra.domain.Country" table="country">
        <id name="id" type="string">
            <column name="country_id" length="3" />
            <generator class="assigned" />
        </id>
        <property name="name" type="string">
            <column name="name" length="40" not-null="true" />
        </property>
        <set name="shareholders" inverse="true">
            <key>
                <column name="citizenship" length="3" />
            </key>
            <one-to-many class="com.schinvest.lra.domain.Shareholder" />
        </set>
        <set name="contracts" inverse="true">
            <key>
                <column name="country_id" length="3" />
            </key>
            <one-to-many class="com.schinvest.lra.domain.Contract" />
        </set>
    </class>
</hibernate-mapping>
and
Quote:
hibernate-mapping>
    <class name="com.schinvest.lra.domain.Shareholder" table="shareholder">
        <id name="id" type="int">
            <column name="shareholder_id" />
            <generator class="assigned" />
        </id>
        <many-to-one name="shareholderType" class="com.schinvest.lra.domain.ShareholderType" fetch="select">
            <column name="type" not-null="true" />
        </many-to-one>
        <many-to-one name="country" class="com.schinvest.lra.domain.Country" fetch="select">
            <column name="citizenship" length="3" />
        </many-to-one>
        <property name="nif" type="string">
            <column name="NIF" length="10" />
        </property>
        <property name="name" type="string">
            <column name="name" length="80" not-null="true" />
        </property>
        <property name="lastName" type="string">
            <column name="last_name" length="40" />
        </property>
        <property name="isResident" type="java.lang.Boolean">
            <column name="is_resident" />
        </property>
        <property name="isCreditEntity" type="java.lang.Boolean">
            <column name="is_credit_entity" />
        </property>
        <set name="contractShareholders" inverse="true">
            <key>
                <column name="shareholder_id" not-null="true" />
            </key>
            <one-to-many class="com.schinvest.lra.domain.ContractShareholder" />
        </set>
    </class>
</hibernate-mapping>
The log files says:
Code:
!ENTRY org.eclipse.jface 4 2 2006-02-14 20:04:36.890
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jface".
!STACK 0
org.hibernate.LazyInitializationException: illegal access to loading collection....
I suspect it is a problem with the association between Country and Shareholders for examples, but I don't see the reason why?
I have seen another post about the Lazy initialization, but I didn't found a real solution for this common problem.
On the 
Country generated class I have a method like this: 
Set getShareholders(){} and on the Shareholder class a method like this:
Country 
getContry(){}
¿Please could you tell me what I am doing wrong?
The *.hbm.xml files where generated using hibernate tool (latest beta version)
Thanks in advance,
David Leal