-->
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: problem with idbag
PostPosted: Mon Jul 14, 2008 4:21 pm 
Newbie

Joined: Wed Sep 06, 2006 8:33 am
Posts: 19
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 15, 2008 4:39 pm 
Newbie

Joined: Wed Sep 06, 2006 8:33 am
Posts: 19
Fixed.

My new 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 name="pTiposMidia" lazy="false" cascade="none" table="VeiculoTipoMidia" >
      <collection-id column="pCodigo" type="Guid">
        <generator class="guid.comb" />
      </collection-id>
      <key column="pVeiculo" />
      <element column="pTipoMidia" type="Test.BD.EnumTipoMidia, Test" />
    </idbag>
  </joined-subclass>
</hibernate-mapping>


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.