Hello!
I am receiving this exception (System.InvalidCastException) on save a object:
'Object must implement IConvertible'
Ok, my class:
Code:
public abstract class Veiculo
{
private int pCodigo;
private string pNome;
[imagine default gets and sets here ;)]
public Veiculo()
{
this.Categorias = new List<Categoria>();
}
}
public class OutroVeiculo : Veiculo
{
private IList<EnumTipoMidia> pTiposMidia;
public virtual IList<EnumTipoMidia> TiposMidia
{
get { return this.pTiposMidia; }
set { this.pTiposMidia = value; }
}
}
public enum EnumTipoMidia
{
Midia1 = 0,
Midia2 = 1,
Midia3 = 2
}
And my mapping:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Test.BD" assembly="Test" default-access="field">
<class name="Veiculo" lazy="false">
<id name="pCodigo">
<generator class="identity" />
</id>
<property name="pNome" />
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Test.BD" assembly="Test" default-access="field">
<joined-subclass extends="Veiculo" name="OutroVeiculo">
<key column="pCodigo"/>
<idbag table="VeiculoTipoMidia" name="pTiposMidia">
<collection-id column="pCodigo" type="Int32">
<generator class="identity"/>
</collection-id>
<key column="pVeiculo" />
<element column="pTipoMidia" type="Test.BD.EnumTipoMidia, Test" />
</idbag>
</joined-subclass>
</hibernate-mapping>
Ok... when i create a new object and add 2 enums to list and try save a object i receive this exception. I enable the log4net to trace the error and i see:
Quote:
(...)
16:59:59.681 [12] DEBUG NHibernate.SQL - Batch command: INSERT INTO VeiculoTipoMidia (pVeiculo, pTipoMidia) VALUES (@p0, @p1); @p0 = '11', @p1 = '0'
Batch command: INSERT INTO VeiculoTipoMidia (pVeiculo, pTipoMidia) VALUES (@p0, @p1); @p0 = '11', @p1 = '1'
Batch command: INSERT INTO VeiculoTipoMidia (pVeiculo, pTipoMidia) VALUES (@p0, @p1); @p0 = '11', @p1 = '2'
(...)
16:59:59.769 [12] DEBUG NHibernate.SQL - Batch command: UPDATE VeiculoTipoMidia SET pTipoMidia = @p0 WHERE pCodigo = @p1; @p0 = '0', @p1 = 'System.Object'
Batch command: UPDATE VeiculoTipoMidia SET pTipoMidia = @p0 WHERE pCodigo = @p1; @p0 = '1', @p1 = 'System.Object'
(...)
WTF! 'System.Object'? Why?
I am using the NHibernate 2.0.0Beta1, MS SQL 2005
I see in the JIRA problem with idbag and oldversions of nhibernate..
it´s a bug in my mapping? Its a bug in my brain?
Thanks for any help and sorry my poor english