-->
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.  [ 10 posts ] 
Author Message
 Post subject: NHibernate 1.2.0 Mapping problem
PostPosted: Fri Jul 13, 2007 6:15 am 
Newbie

Joined: Thu Jul 12, 2007 1:13 am
Posts: 17
can anyone tell me what should be the mapping file structure for NHibernate 1.2.0.Currently I'm using this mapping file and it is giving an exception : MappingException.

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class
name="NHDemo.Status,NHDemo" table="status">
<id
name="statusCd"
type="long"
column="STATUS_CD"
>
<generator class="assigned" />
</id>
<property
name="statusDesc"
type="String"
column="STATUS_DESC"
length="50"
/>
<property
name="statusId"
type="long"
column="STATUS_ID"
length="18"
/>
</class>
</hibernate-mapping>

Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 1.2.0

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 7:04 am 
Beginner
Beginner

Joined: Tue Jul 10, 2007 5:27 am
Posts: 34
Location: Belgium
change

urn:nhibernate-mapping-2.0

to

urn:nhibernate-mapping-2.2

_________________
Davy Brion
http://ralinx.wordpress.com


Top
 Profile  
 
 Post subject: But It doesn't solv the problem
PostPosted: Fri Jul 13, 2007 7:10 am 
Newbie

Joined: Thu Jul 12, 2007 1:13 am
Posts: 17
But I'm still getting error :

An unhandled exception of type 'NHibernate.MappingException' occurred in NHibernate.dll

Additional information: Unknown entity class: NHDemo.Status


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 7:44 am 
Beginner
Beginner

Joined: Tue Jul 10, 2007 5:27 am
Posts: 34
Location: Belgium
can you post the code that causes the exception?

_________________
Davy Brion
http://ralinx.wordpress.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 7:59 am 
Newbie

Joined: Thu Jul 12, 2007 1:13 am
Posts: 17
namespace NHDemo
{
class Program
{
static void Main(string[] args)
{

Configuration conf = new Configuration();
conf.AddAssembly("NHDemo");
NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize("", System.Reflection.Assembly.GetExecutingAssembly());
conf.AddXmlFile("Status.hbm.xml");
ISessionFactory factory = conf.BuildSessionFactory();
ISession session = factory.OpenSession();
session.Flush();
Int64 x = 1;
Object y = (Object)x;
NHDemo.Status newUser = (NHDemo.Status)session.Load(typeof(Status),y);
session.Close();
conn.Close();
}
}
}

Mapping:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class
name="NHDemo.Status,NHDemo" table="status">
<id
name="statusCd"
type="long"
column="STATUS_CD"
>
<generator class="assigned" />
</id>
<property
name="statusDesc"
type="String"
column="STATUS_DESC"
length="50"
/>
<property
name="statusId"
type="long"
column="STATUS_ID"
length="18"
/>
</class>
</hibernate-mapping>

Class File:
namespace NHDemo
{
public class Status
{
/** identifier field */
private long _statusCd;

/** nullable persistent field */
private String _statusDesc;

/** nullable persistent field */
private long _statusId;

public Status(long statusCd, String statusDesc, long statusId)
{
this.statusCd = statusCd;
this.statusDesc = statusDesc;
this.statusId = statusId;

}

/** default constructor */
public Status()
{
}

public virtual long statusCd
{
get { return _statusCd; }
set { _statusCd = value; }
}

public virtual string statusDesc
{
get { return _statusDesc; }
set { _statusDesc = value; }
}

public virtual long statusId
{
get { return _statusId; }
set { _statusId = value; }
}

}
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 8:03 am 
Newbie

Joined: Thu Jul 12, 2007 1:13 am
Posts: 17
If you need any thing else kindly tell me.....actually this is really important because I have to use Hibernate queries in .NET


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 8:24 am 
Beginner
Beginner

Joined: Tue Jul 10, 2007 5:27 am
Posts: 34
Location: Belgium
what happens if you just do this:

Code:
    class Program
    {
        static void Main(string[] args)
        {
           
            Configuration conf = new Configuration();
            conf.AddXmlFile("Status.hbm.xml");
            ISessionFactory factory = conf.BuildSessionFactory();
            ISession session = factory.OpenSession();
            NHDemo.Status newUser = session.Get<NHDemo.Status>(1);
            session.Close();
        }
    }


_________________
Davy Brion
http://ralinx.wordpress.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 8:31 am 
Newbie

Joined: Thu Jul 12, 2007 1:13 am
Posts: 17
It is giving Identifier Mismatch Error


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 8:32 am 
Newbie

Joined: Thu Jul 12, 2007 1:13 am
Posts: 17
Yaa It's working Now actually that method takes an Object. Thanx.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 8:34 am 
Newbie

Joined: Thu Jul 12, 2007 1:13 am
Posts: 17
Actually what the challenge i'm facing is that the application on which I'm working is built on JAVA with Oracle data base so they are using Hibernate.Now I need to Migrate from Java to .NET with the same data base and using the same HQL queries..... is there any way that it can be done.


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