-->
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.  [ 12 posts ] 
Author Message
 Post subject: samples to download for beginners
PostPosted: Tue Jun 26, 2007 5:53 pm 
Regular
Regular

Joined: Tue Jun 26, 2007 11:50 am
Posts: 105
Is there any very simple samples to donwload for beginners (on this website or anywhere else) ? I particulary research a sample that uses NHibernate.Mapping.Attributes.

thanks,

mathmax


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 1:27 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
There should be some samples linked from the Wiki. They don't use NHMA though, as far as I know.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 7:55 am 
Regular
Regular

Joined: Tue Jun 26, 2007 11:50 am
Posts: 105
Could you help me, please. I don't understand why this code doesn't work with the latest version of nhibernate whereas it works with nhibernate for .NET 1.1.

namespace NhbernateTest
{
class Program
{
static void Main(string[] args)
{
log4net.Config.XmlConfigurator.Configure();
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");
cfg.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MsSql2005Dialect");
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, ConfigurationManager.ConnectionStrings[1].ConnectionString);

cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.Driver.SqlClientDriver");
System.IO.MemoryStream flux = new System.IO.MemoryStream();
NHibernate.Mapping.Attributes.HbmSerializer.Default.Validate = true;
NHibernate.Mapping.Attributes.HbmSerializer.Default.HbmDefaultAccess = "field.camelcase-underscore";

NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize(flux, System.Reflection.Assembly.GetExecutingAssembly());
flux.Position = 0;
cfg.AddInputStream(flux);
flux.Close();

NHibernate.ISessionFactory _sessionFactory = cfg.BuildSessionFactory();

User newUser = new User();
newUser.UserName = "Joseph Cool";
newUser.Password = "abc123";
newUser.EmailAddress = "joe@cool.com";
newUser.LastLogon = DateTime.Now;

NHibernate.ISession session = null;
NHibernate.ITransaction transaction = null;

try
{
session = _sessionFactory.OpenSession();
transaction = session.BeginTransaction();

session.SaveOrUpdate(newUser);

transaction.Commit();
}
catch(Exception e)
{
if (transaction != null)
transaction.Rollback();
throw;
}
finally
{
if (session != null)
session.Close();
}
}
}

[NHibernate.Mapping.Attributes.Class(Table = "users")]
public class User
{
private int id;
private string userName;
private string password;
private string emailAddress;
private DateTime lastLogon;

public User()
{
}

[NHibernate.Mapping.Attributes.Id(Name = "LogonId")]
[NHibernate.Mapping.Attributes.Generator(1, Class = "native")]
public virtual int Id
{
get { return id; }
}

[NHibernate.Mapping.Attributes.Property(Column = "Name")]
public virtual string UserName
{
get { return userName; }
set { userName = value; }
}

[NHibernate.Mapping.Attributes.Property]
public virtual string Password
{
get { return password; }
set { password = value; }
}

[NHibernate.Mapping.Attributes.Property]
public virtual string EmailAddress
{
get { return emailAddress; }
set { emailAddress = value; }
}

[NHibernate.Mapping.Attributes.Property]
public virtual DateTime LastLogon
{
get { return lastLogon; }
set { lastLogon = value; }
}
}
}


the error occurs at line " cfg.AddInputStream(flux); " and the message is : Could not compile the mapping document: (unknown)

Do you have an idea of the problem ?

Thank you in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 8:04 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
http://www.hibernate.org/Documentation/ ... otingGuide - see the general rule.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 8:17 am 
Regular
Regular

Joined: Tue Jun 26, 2007 11:50 am
Posts: 105
Do you think it is a bug ?

This is my first test using NHMA. I don't know how to make it work because I don't have any sample to see how NHMA works. The only one I found was this one. It wirked with .net 1 but not with .net 2.If you have any sample, even very simple, that uses NHMA I would be very interrested.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 7:33 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Did you actually visit the link?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 7:56 am 
Regular
Regular

Joined: Tue Jun 26, 2007 11:50 am
Posts: 105
yes it is a bug report. That's why I asked you if it is a bug.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 8:04 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Huh? Bug report? Where does it say "bug report"? It's a page to help people solve problems with NHibernate. In particular, the general rule I asked you to read and follow is:
Quote:
First, a general rule: many exceptions that NHibernate throws are actually wrappers over other exceptions. The underlying exception can be found by examining the InnerException property. This exception may in turn contain another exception and so on. You are usually interested in the innermost exception.


So please show us the inner exception of the one you are getting.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 11:25 am 
Regular
Regular

Joined: Tue Jun 26, 2007 11:50 am
Posts: 105
InnerException :

Could not instantiate dialect class NHibernate.JetDriver.JetDialect, NHibernate.JetDriver


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 11:46 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
And the inner exception of that?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 12:01 pm 
Regular
Regular

Joined: Tue Jun 26, 2007 11:50 am
Posts: 105
Impossible to load file or assembly 'NHibernate, Version=1.0.2.0, Culture=neutral, PublicKeyToken=154fdcb44c4484fc' or one of its dependencies. (Exception de HRESULT : 0x80131040)":"NHibernate, Version=1.0.2.0, Culture=neutral, PublicKeyToken=154fdcb44c4484fc


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 12:15 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Okay, now you should have all the data you need to solve this on your own, or maybe with a bit of Google search.

Hint: you told us you're using the latest version of NHibernate (which is 1.2.0), and yet the assembly that could not be loaded belongs to NHibernate 1.0.2.


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