-->
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.  [ 4 posts ] 
Author Message
 Post subject: Error in 1.0 - System.InvalidCast [upd] wrong table in sql
PostPosted: Wed Oct 12, 2005 5:10 am 
Newbie

Joined: Mon Jun 20, 2005 7:30 am
Posts: 8
Hi

I upgraded NHibernate from 0.9.1 to 1.0.0.0. Then I get this error

System.InvalidCastException: Invalid attempt to GetBytes on column 'UpdatedBy0_'. The GetBytes function can only be used on columns of type Text, NText, or Image.

The mapping for this column is

<property name="UpdatedBy" column="UpdatedBy" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate"/>

and in the database the column is int(4) and allows null

Any ideas?

Regards,
Haukur


Last edited by haukur on Wed Oct 12, 2005 12:23 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 5:28 am 
Newbie

Joined: Mon Jun 20, 2005 7:30 am
Posts: 8
Update.. I have other tables with the same column that is mapped exactly the same and it works fine.

The difference with the table that dont work is that is contains a discriminator column. Here is the full mapping

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ValueObjects.General.CigEntity, ValueObjects" table="c_ge_CigEntity" discriminator-value="-99">
<id name="CId" column="CId" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<discriminator column="Type" type="Int32"/>
<property name="IsSearchable" column="IsSearchable" type="Boolean"/>
<property name="ProviderId" column="ProviderId"/>
<property name="OriginId" column="OriginId"/>
<property name="Inserted" column="Inserted" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate"/>
<property name="InsertedBy" column="InsertedBy"/>
<property name="Updated" column="Updated" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate"/>
<property name="UpdatedBy" column="UpdatedBy" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate"/>
<property name="Disabled" column="Disabled" type="Boolean"/>

<many-to-one name="Origin" class="ValueObjects.General.Lookup.Origin,ValueObjects" column="OriginId" insert="false" update="false"/>

<one-to-one name="Detail"
class="ValueObjects.General.CigEntityDetail,ValueObjects"
constrained="false"
cascade="none"
/>

<bag name="Address" inverse="true" cascade="all-delete-orphan" lazy="true">
<key column="CId"/>
<one-to-many class="ValueObjects.General.Address.Address,ValueObjects"/>
</bag>

<bag name="Identification" inverse="true" cascade="all-delete-orphan" lazy="true">
<key column="CId"/>
<one-to-many class="ValueObjects.General.Identification.IdNumber,ValueObjects"/>
</bag>

<bag name="PhoneNumber" inverse="true" cascade="all-delete-orphan" lazy="true">
<key column="CId"/>
<one-to-many class="ValueObjects.General.Phone.PhoneNumber,ValueObjects"/>
</bag>

<subclass name="ValueObjects.General.CigEntityIndividual, ValueObjects" discriminator-value="1">
<many-to-one name="Individual" class="ValueObjects.General.Individual.Individual, ValueObjects" column="CId" insert="false" update="false"/>
</subclass>

<subclass name="ValueObjects.General.CigEntityCompany, ValueObjects" discriminator-value="2">
<many-to-one name="Company" class="ValueObjects.General.Company.Company, ValueObjects" column="CId" insert="false" update="false"/>
</subclass>
</class>
</hibernate-mapping>

This worked fine before I updated to 1.0

Any??

Regards,
Haukur


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 9:31 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Please double- and triple-check you don't have any old copy of Nullables and Nullables.NHibernate lying around. Incompatible versions are known to cause this kind of problems.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 12:11 pm 
Newbie

Joined: Mon Jun 20, 2005 7:30 am
Posts: 8
Hi

I found out that the error was misleading.

The case is following.

I have a value object named CigEntity that maps to a table name c_ge_CigEntity

In other namespace there is a value object named CigEntityDP, that inherits from CigEntity, which has 2 subclasses - CigEntityIndividual and CigEntityCompany. Both these subclasses has mapping file pointing to the table c_dp_CigEntity.

It seems that when loading value object CigEntity -> from table c_ge_CigEntity with List, the table c_dp_CigEntity is used in the sql instead of c_ge_CigEntity. It works fine with Load.

I tried to discard the mapping file for CigEntityIndividualDP and CigEntityCompanyDP from the dll and then all worked fine.

This problem is only in RC1 and newer - not in the beta.

Here is mapping for CigEntityIndividualDP

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ValueObjects.DP.General.CigEntityIndividualDP, ValueObjects" table="c_dp_CigEntity" discriminator-value="-99">
<id name="CreditinfoId" column="CreditinfoId" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<!--<discriminator column="Type" type="Int32"/>-->
<property name="IsSearchable" column="IsSearchable" type="Boolean"/>
<property name="Type" column="Type"/>
<property name="ProviderId" column="ProviderId"/>
<property name="OriginId" column="OriginId"/>
<property name="Inserted" column="Inserted" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate"/>
<property name="InsertedBy" column="InsertedBy"/>
<property name="Updated" column="Updated" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate"/>
<property name="UpdatedBy" column="UpdatedBy"/>
<property name="Disabled" column="Disabled" type="Boolean"/>

</class>
</hibernate-mapping>

Here is mapping for CigEntityCompanyDP
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ValueObjects.DP.General.CigEntityCompanyDP, ValueObjects" table="c_dp_CigEntity" discriminator-value="-99">
<id name="CreditinfoId" column="CreditinfoId" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<!--<discriminator column="Type" type="Int32"/>-->
<property name="IsSearchable" column="IsSearchable" type="Boolean"/>
<property name="Type" column="Type"/>
<property name="ProviderId" column="ProviderId"/>
<property name="OriginId" column="OriginId"/>
<property name="Inserted" column="Inserted" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate"/>
<property name="InsertedBy" column="InsertedBy"/>
<property name="Updated" column="Updated" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate"/>
<property name="UpdatedBy" column="UpdatedBy"/>
<property name="Disabled" column="Disabled" type="Boolean"/>

</class>
</hibernate-mapping>

Any suggestions?

Regards,
Haukur


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