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.  [ 3 posts ] 
Author Message
 Post subject: problem: "identifier mapping has wrong number of column
PostPosted: Wed Nov 07, 2007 11:20 am 
Newbie

Joined: Wed Nov 07, 2007 7:12 am
Posts: 4
Hi!
I've a little problem! I'm trying to realize a web application in VB.net, and I'm mapping 2 classes, autors (Autore), and artworks (Opera): they are 'many to many' related objects; so in the db I've three tables: A_AUT, autors, DN_OG, artworks, DR_AUT, table with associations.
Any suggestions?
Thank you,
Matteo Figus

Hibernate version: NHibernate 1.2.0
Mapping documents:
Autore.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    namespace="NHWebSite" assembly="NHWebSite">

  <class name="NHWebSite.NHWebSite.Autore, NHWebSite" table="A_AUT">
    <id name="COD_AUT">
      <column name="COD_AUT" sql-type="int(4)" not-null="true"/>
      <generator class="increment" />
    </id>
    <property name="Name" column="Name" type="string" not-null="true" />
    <set name="Opere" table="DR_AUT" lazy="true" inverse="true" cascade="all">
      <key column="COD_AUT"/>
      <many-to-many column="COD_OG" class="NHWebSite.NHWebSite.Opera, NHWebSite"/>
    </set>
  </class>
</hibernate-mapping>

Opera.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    namespace="NHWebSite" assembly="NHWebSite">

  <class name="NHWebSite.NHWebSite.Opera, NHWebSite" table="DN_OG">
    <id name="COD_OG">
      <column name="COD_OG" sql-type="int(4)" not-null="true"/>
      <generator class="increment" />
    </id>
    <property name="SGTT_OG" column="SGTT_OG" type="string" not-null="true" />
    <set name="Autori" table="DR_AUT" lazy="true" inverse="true" cascade="all">
      <key column="COD_OG"/>
      <many-to-many column="COD_AUT" class="NHWebSite.NHWebSite.Autore, NHWebSite"/>
    </set>
  </class>
</hibernate-mapping>

Classes:
Autore.vb
Code:
Namespace NHWebSite

    Public Class Autore
        Private _COD_AUT As Integer
        Private _Name As String
        Private _Opere As IList(Of Opera)

        Public Overridable Property COD_AUT()
            Get
                Return _COD_AUT
            End Get
            Set(ByVal value)
                _COD_AUT = value
            End Set
        End Property

        Public Overridable Property Name()
            Get
                Return _Name
            End Get
            Set(ByVal value)
                _Name = value
            End Set
        End Property

        Public Overridable Property Opere()
            Get
                Return _Opere
            End Get
            Set(ByVal value)
                _Opere = value
            End Set
        End Property
    End Class

End Namespace

Opera.vb
Code:
Namespace NHWebSite

    Public Class Opera
        Private _COD_OG As Integer
        Private _SGTT_OG As String
        Private _Autori As IList(Of Autore)

        Public Overridable Property COD_OG()
            Get
                Return _COD_OG
            End Get
            Set(ByVal value)
                _COD_OG = value
            End Set
        End Property

        Public Overridable Property SGTT_OG()
            Get
                Return _SGTT_OG
            End Get
            Set(ByVal value)
                _SGTT_OG = value
            End Set
        End Property

        Public Overridable Property Autori()
            Get
                Return _Autori
            End Get
            Set(ByVal value)
                _Autori = value
            End Set
        End Property

    End Class
End Namespace

NHibernateHelper.vb
Code:
Imports System
Imports System.Web
Imports NHibernate
Imports NHibernate.Cfg

Namespace NHWebSite
    Public NotInheritable Class NHibernateHelper

        Public Const CurrentSessionKey As String = "nhibernate.current_session"
        Public Shared ReadOnly sessionFactory As ISessionFactory

        Shared Sub New()
            Dim x As New NHibernate.Cfg.Configuration
            sessionFactory = x.Configure.BuildSessionFactory()
        End Sub

        Public Shared Function GetCurrentSession() As ISession
            Dim context As HttpContext = HttpContext.Current
            Dim currentSession As ISession = context.Items(CurrentSessionKey)
            If currentSession Is Nothing Then
                currentSession = sessionFactory.OpenSession()
                context.Items(CurrentSessionKey) = currentSession
            End If
            Return currentSession
        End Function

        Public Shared Sub CloseSession()
            Dim context As HttpContext = HttpContext.Current
            Dim currentSession As ISession = context.Items(CurrentSessionKey)
            If currentSession Is Nothing Then Return
            currentSession.Close()
            context.Items.Remove(CurrentSessionKey)
        End Sub

        Public Shared Sub CloseSessionFactory()
            If sessionFactory IsNot Nothing Then sessionFactory.Close()
        End Sub

    End Class
End Namespace


Code between sessionFactory.openSession() and session.close(): None for now. Just mapped and tryin to build without errors.

Full stack trace of any exception that occurs:
"identifier mapping has wrong number of columns: Autore type: Object "

Code:
[MappingException: identifier mapping has wrong number of columns: Autore type: Object]
   NHibernate.Mapping.RootClass.Validate(IMapping mapping) +203
   NHibernate.Cfg.Configuration.Validate() +224
   NHibernate.Cfg.Configuration.BuildSessionFactory() +41
   NHWebSite.NHWebSite.NHibernateHelper..cctor() in C:\Users\Matteo\Documents\Visual Studio 2005\Projects\NHWebSite\NHWebSite\Repository\NHibernateHelper.vb:14

[TypeInitializationException: L'inizializzatore di tipo di 'NHWebSite.NHWebSite.NHibernateHelper' ha generato un'eccezione.]
   NHWebSite.NHWebSite.NHibernateHelper.GetCurrentSession() in C:\Users\Matteo\Documents\Visual Studio 2005\Projects\NHWebSite\NHWebSite\Repository\NHibernateHelper.vb:25
   NHWebSite._Default.Page_Load(Object sender, EventArgs e) in C:\Users\Matteo\Documents\Visual Studio 2005\Projects\NHWebSite\NHWebSite\Default.aspx.vb:12
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061



Name and version of the database you are using: Ms sql server 2005

Tables:
A_AUT
- COD_AUT - int(4) - (Primary Key)
- Name - nchar(50)

DN_OG
- COD_OG - int(4) - (Primary Key)
- SGTT_OG - nchar(50)

DR_AUT
- COD_AUT - int(4) - (Primary Key)
- COD_OG - int(4) - (Primary Key)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 08, 2007 8:42 am 
Newbie

Joined: Wed Nov 07, 2007 7:12 am
Posts: 4
Nobody can help me? Please, I don't know what to do...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 08, 2007 5:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
Try removing inverse="true" attribute from one of the <set> elements. It may or may not be your problem; but having both ends as inversed is definitely erroneous.

_________________
Karl Chu


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