-->
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.  [ 5 posts ] 
Author Message
 Post subject: Unknown entity class: System.Int32
PostPosted: Fri Dec 14, 2007 12:48 am 
Newbie

Joined: Fri Dec 14, 2007 12:15 am
Posts: 3
Please help. I receive the following error: Unknown entity class: System.Int32

I've tried different settings/attributes for the many-to-one tag without any success. Everything works fine when I remove the foreign-key constraints from the database and the many-to-one tag. My *.hbm.xml files are set as Embedded Resources.

I did a lot of searching already and the little I found wasn't helpful. Is this a bug, or am I missing something here?



NHibernate version: 1.2.1 GA

Mapping documents:

Project.hbm.xml
Code:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"  assembly="Testing_Console" namespace="Testing_Console">
   <class name="Testing_Console.Project, Testing_Console" table="projects">
      <id name="Id" column="projects_id" type="Int32">
         <generator class="identity" />
      </id>
      
      <property name="Name" column="name" type="String" length="50" not-null="true" />
   </class>
</hibernate-mapping>


MixDesign.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"  assembly="Testing_Console" namespace="Testing_Console">
   <class name="Testing_Console.MixDesign, Testing_Console" table="mix_designs">
      <id name="Id" column="mix_designs_id" type="Int32">
         <generator class="identity" />
      </id>
      <property name="ProjectId" column="projects_id" not-null="false" type="Int32"/>
      <property name="Name" column="name" type="String" length="50"/>
      <property name="SpecifiedStrength" column="specified_strength" type="Int32"/>
      <many-to-one name="ProjectId" column="projects_id" foreign-key="FK_mix_designs_projects" class="Project" />
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
            Configuration cfg = new Configuration();
            cfg.AddAssembly("Testing_Console");

            ISessionFactory factory = cfg.BuildSessionFactory();
            ISession session = factory.OpenSession();
            ITransaction transaction = session.BeginTransaction();

            MixDesign mix = new MixDesign();
            mix.Name = "C4000";
            mix.SpecifiedStrength = 4000;

            session.Save(mix);
            transaction.Commit();
            session.Close();

Full stack trace of any exception that occurs:
Code:
      StackTrace   "   at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(Type theClass) in D:\\Program Files\\NHibernate\\src\\src\\NHibernate\\Impl\\SessionFactoryImpl.cs:line 608\r\n   at NHibernate.Impl.SessionImpl.GetClassPersister(Type theClass) in D:\\Program Files\\NHibernate\\src\\src\\NHibernate\\Impl\\SessionImpl.cs:line 3629\r\n   at NHibernate.Impl.SessionImpl.GetEntityPersister(Object obj) in D:\\Program Files\\NHibernate\\src\\src\\NHibernate\\Impl\\SessionImpl.cs:line 3637\r\n   at NHibernate.Impl.SessionImpl.IsUnsaved(Object obj, Boolean earlyInsert, Object self) in D:\\Program Files\\NHibernate\\src\\src\\NHibernate\\Impl\\SessionImpl.cs:line 1171\r\n   at NHibernate.Impl.SessionImpl.NullifyTransientReferences(Object value, IType type, Boolean earlyInsert, Object self) in D:\\Program Files\\NHibernate\\src\\src\\NHibernate\\Impl\\SessionImpl.cs:line 1102\r\n   at NHibernate.Impl.SessionImpl.NullifyTransientReferences(Object[] values, IType[] types, Boolean earlyInsert, Object self) in D:\\Program Files\\NHibernate\\src\\src\\NHibernate\\Impl\\SessionImpl.cs:line 1081\r\n   at NHibernate.Impl.SessionImpl.DoSave(Object theObj, EntityKey key, IEntityPersister persister, Boolean replicate, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything) in D:\\Program Files\\NHibernate\\src\\src\\NHibernate\\Impl\\SessionImpl.cs:line 953\r\n   at NHibernate.Impl.SessionImpl.DoSave(Object obj, Object id, IEntityPersister persister, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything) in D:\\Program Files\\NHibernate\\src\\src\\NHibernate\\Impl\\SessionImpl.cs:line 872\r\n   at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything) in D:\\Program Files\\NHibernate\\src\\src\\NHibernate\\Impl\\SessionImpl.cs:line 767\r\n   at NHibernate.Impl.SessionImpl.Save(Object obj) in D:\\Program Files\\NHibernate\\src\\src\\NHibernate\\Impl\\SessionImpl.cs:line 708\r\n   at Testing_Console.Program.Main(String[] args) in D:\\Projects\\Testing and Experimental\\Testing-Console\\Testing-Console\\Program.cs:line 24\r\n   at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)\r\n   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n   at System.Threading.ThreadHelper.ThreadStart()"   string



Name and version of the database you are using:
SQL Server 2005 SP2


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 14, 2007 10:28 am 
Beginner
Beginner

Joined: Tue May 02, 2006 8:04 am
Posts: 34
<property name="ProjectId" column="projects_id" not-null="false" type="Int32"/>

<many-to-one name="ProjectId" column="projects_id" foreign-key="FK_mix_designs_projects" class="Project" />

Don't know if this will fix it, but this sure looks wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 14, 2007 10:55 am 
Newbie

Joined: Fri Dec 14, 2007 12:15 am
Posts: 3
.ben wrote:
<property name="ProjectId" column="projects_id" not-null="false" type="Int32"/>

<many-to-one name="ProjectId" column="projects_id" foreign-key="FK_mix_designs_projects" class="Project" />

Don't know if this will fix it, but this sure looks wrong.


ben, I don't understand what you are suggesting as a solution; you just repeated what I already have.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 14, 2007 11:35 am 
Beginner
Beginner

Joined: Tue May 02, 2006 8:04 am
Posts: 34
Remove this from your mapping file:

<property name="ProjectId" column="projects_id" not-null="false" type="Int32"/>

Keep this, but change name to Project and add a property called Project to your class

So :
<many-to-one name="ProjectId" column="projects_id" foreign-key="FK_mix_designs_projects" class="Project" />

will become

<many-to-one name="Project" column="projects_id" foreign-key="FK_mix_designs_projects" class="Project" />


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 14, 2007 12:26 pm 
Newbie

Joined: Fri Dec 14, 2007 12:15 am
Posts: 3
.ben wrote:
Remove this from your mapping file:

<property name="ProjectId" column="projects_id" not-null="false" type="Int32"/>

Keep this, but change name to Project and add a property called Project to your class

So :
<many-to-one name="ProjectId" column="projects_id" foreign-key="FK_mix_designs_projects" class="Project" />

will become

<many-to-one name="Project" column="projects_id" foreign-key="FK_mix_designs_projects" class="Project" />


Excellent. It works now. THANKS!

For anyone else who experiences this mistake:

I had not added a property of type Project to the MixDesign class. It didn't matter what I changed in the mapping file since the class was incorrectly configured. It kept trying to map to System.Int32 because the property I created in the MixDesign class was for the projects_id column (that I named ProjectId, an Int32), and not the Project entity.

Corrected MixDesign class
Code:
    public class MixDesign
    {
        public MixDesign()
        {

        }

        private int _id;

        public virtual int Id
        {
            get { return _id; }
            set { _id = value; }
        }

        private Project _project;

        public virtual Project Project
        {
            get { return _project; }
            set { _project = value; }
        }   

        private String _name;

        public virtual String Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private Plant _plant;

        public virtual Plant Plant
        {
            get { return _plant; }
            set { _plant = value; }
        }

        private int _specifiedStrength;

        public virtual int SpecifiedStrength
        {
            get { return _specifiedStrength; }
            set { _specifiedStrength = value; }
        }
    }


Corrected MixDesign.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"  assembly="Testing_Console" namespace="Testing_Console">
   <class name="Testing_Console.MixDesign, Testing_Console" table="mix_designs">
      <id name="Id" column="mix_designs_id" type="Int32">
         <generator class="identity" />
      </id>
      <property name="Name" column="name" type="String" length="50"/>
      <property name="PlantId" column="plants_id" type="Int32" />
      <property name="SpecifiedStrength" column="specified_strength" type="Int32"/>
      <many-to-one name="Project" column="projects_id" foreign-key="FK_mix_designs_projects" class="Project" />
   </class>
</hibernate-mapping>


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