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: NHibernate, could not load an entity when column exists in t
PostPosted: Tue May 25, 2010 8:56 am 
Newbie

Joined: Thu Nov 05, 2009 11:36 am
Posts: 6
This is probably a simple question to answer but I just can't figure it out.

I have a "Company" class with a many-to-one to "Address" which has a many to one to a composite id in "City". When I load a "Company" it loads the "Address", but if I call any property of "Address" I get the error:

Code:
{"could not load an entity: [IDI.Domain.Entities.Address#2213][SQL: SELECT address0_.AddressId as AddressId13_0_, address0_.Street as Street13_0_, address0_.floor as floor13_0_, address0_.room as room13_0_, address0_.postalcode as postalcode13_0_, address0_.CountryCode as CountryC6_13_0_, address0_.CityName as CityName13_0_ FROM Address address0_ WHERE address0_.AddressId=?]"}

The inner exception is:

Code:
{"Invalid column name 'CountryCode'.\r\nInvalid column name 'CityName'."}


What I don't understand is that I can run the query in sql server 2005 and it works, furthermore both those columns exist in the address table.

Here are my HBMs:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="IDI.Domain" namespace="IDI.Domain.Entities" >
    <class name="IDI.Domain.Entities.Company,IDI.Domain" table="Companies">
        <id column="CompanyId" name="CompanyId" unsaved-value="0">
            <generator class="native"></generator>
        </id>
        <property column="Name" name="Name" not-null="true" type="String"></property>
        <property column="NameEng" name="NameEng" not-null="false" type="String"></property>
        <property column="Description" name="Description" not-null="false" type="String"></property>
        <property column="DescriptionEng" name="DescriptionEng" not-null="false" type="String"></property>
        <many-to-one name="Address" column="AddressId" not-null="false" cascade="save-update" class="IDI.Domain.Entities.Address,IDI.Domain"></many-to-one>
        <property column="Telephone" name="Telephone" not-null="false" type="String"></property>
        <property column="TelephoneTwo" name="TelephoneTwo" not-null="false" type="String"></property>
        <property column="Fax" name="Fax" not-null="false" type="String"></property>
        <property column="ContactMan" name="ContactMan" not-null="false" type="String"></property>
        <property column="ContactManEng" name="ContactManEng" not-null="false" type="String"></property>
        <property column="Email" name="Email" not-null="false" type="String"></property>       
    </class>
</hibernate-mapping>




Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="IDI.Domain" namespace="IDI.Domain.Entities" >
    <class name="IDI.Domain.Entities.Address,IDI.Domain" table="Address">
        <id name="AddressId" column="AddressId" type="Int32">
            <generator class="native"></generator>
        </id>
        <property name="Street" column="Street" not-null="false" type="String"></property>   
        <property name="Floor" column="floor" not-null="false" type="Int32"></property>
        <property name="Room" column="room" not-null="false" type="Int32"></property>
        <property name="PostalCode" column="postalcode" not-null="false" type="string"></property>
        <many-to-one class="IDI.Domain.Entities.City,IDI.Domain" name="City" update="false" insert="false">
            <column name="CountryCode" sql-type="String" ></column>
            <column name="CityName"  sql-type="String"></column>             
        </many-to-one>
        </class>
</hibernate-mapping>



Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="IDI.Domain" namespace="IDI.Domain.Entities" >
    <class name="IDI.Domain.Entities.City,IDI.Domain" table="Cities">
        <composite-id>
            <key-many-to-one class="IDI.Domain.Entities.Country,IDI.Domain" name="CountryCode" column="CountryCode">
            </key-many-to-one>
            <key-property name="Name" column="Name" type="string"></key-property>
        </composite-id>

    </class>
</hibernate-mapping>

Here is my code that calls the Company:

Code:
IList<BursaUser> user;
            if(String.IsNullOrEmpty(email) && String.IsNullOrEmpty(company))
                return null;
            ICriteria criteria = Session.CreateCriteria(typeof (BursaUser), "user").CreateCriteria("Company", "comp");
            if(String.IsNullOrEmpty(email) || String.IsNullOrEmpty(company) )
            {
                user = String.IsNullOrEmpty(email) ?
                    criteria.Add(Expression.Eq("comp.Name", company)).List<BursaUser>()
                    : criteria.Add(Expression.Eq("user.Email", email)).List<BursaUser>();

            }

And finally here is where i get the error:

"user" was already initialized with the code above:

Code:
if (user.Company.Address.City == null)
                    user.Company.Address.City = new City();

Thanks.


Top
 Profile  
 
 Post subject: Re: NHibernate, could not load an entity when column exists in t
PostPosted: Wed May 26, 2010 2:12 am 
Beginner
Beginner

Joined: Fri Feb 27, 2009 6:07 am
Posts: 38
Location: Moscow,Russia
Types composite id not equals in Address and City:
<key-many-to-one class="IDI.Domain.Entities.Country,IDI.Domain" name="CountryCode" column="CountryCode">
</key-many-to-one>
<column name="CountryCode" sql-type="String" ></column>


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.