-->
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: Error Creating Mapping File
PostPosted: Sun Jan 03, 2010 11:30 am 
Newbie

Joined: Sun Jan 03, 2010 11:20 am
Posts: 3
Hello
I am using NHibernate with mysql. I have created ISessionFactory using the following xml code in the "App.config" file :
<?xml version="1.0" ?>
<configuration>
<configSections>
<section name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler,NHibernate" />
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MySqlDialect</property>
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
<property name="connection.connection_string">SERVER=localhost;DATABASE=nhibernate;UID=root;PASSWORD=localpass;</property>
</session-factory>
</hibernate-configuration>
</configuration>

Now, I have an employee class which has the following declaration :

namespace TotallyNHibernateTest
{
// POCO(Plain Old CLR Object) - Employee
public class Employee
{
private int employeeId;
private string name;

public Employee(int employeeId, string name)
{
this.employeeId = employeeId;
this.name = name;
}

#region Property Accessors
public int EmployeeId
{
set
{
this.employeeId = value;
}
get
{
return this.employeeId;
}
}
public string Name
{
set
{
this.name = value;
}
get
{
return this.name;
}
}
#endregion
}
}

For this class, I have created a mapping file :

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="TotallyNHibernateTest.Employee, TotallyNHibernateTest" table="employee">
<id name="EmployeeId" column="id">
<generator class="assigned"/>
</id>
<property name="Name" column="name"/>
<many-to-one access="field" name="manager" column="manager" cascade="all"/>
</class>
</hibernate-mapping>

The corresponding database table has the following declaration :

CREATE TABLE employee(
id int(11) NOT NULL auto_increment,
name varchar(255) default NULL,
PRIMARY KEY (id)
);


But when I try to create a session factory, an exception occurs, saying "Could not compile the mapping document: TotallyNHibernateTest.Employee.hbm.xml".

I don't have a clue what is going on. Can someone help me please? It will be much appreciated.

I am creating session factory using the following code :

SessionFactory = new Configuration()
.Configure()
.AddAssembly(Assembly.GetCallingAssembly())
.BuildSessionFactory();

Thanx in advance


Top
 Profile  
 
 Post subject: Re: Error Creating Mapping File
PostPosted: Thu Jan 07, 2010 5:44 am 
Newbie

Joined: Sun Jan 03, 2010 11:20 am
Posts: 3
Well, I solved the problem all by myself. The error was in the <property name="dialect">NHibernate.Dialect.MySqlDialect</property> tag of the App.config file. I copied this whole code from this Brilliant(!) Article, and as a result, I was stuck at simple configuration for two days.......Phew, it is over now, what a relief :)

The correct syntax will be :

<property name="dialect">NHibernate.Dialect.MySQLDialect</property>

or

<property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>, if you are using mysql 5

Have fun


Top
 Profile  
 
 Post subject: Re: Error Creating Mapping File
PostPosted: Thu Jan 07, 2010 5:48 am 
Newbie

Joined: Sun Jan 03, 2010 11:20 am
Posts: 3
and one other thing - to enable lazy-loading, which should always be preferred, all the members of a persistent class excluding attributes should be declared as virtual.


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.