-->
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.  [ 9 posts ] 
Author Message
 Post subject: Problem with Configuration New to NHibernate
PostPosted: Sat Mar 08, 2008 12:38 am 
Newbie

Joined: Sat Mar 08, 2008 12:24 am
Posts: 4
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
1.21 GA

Mapping documents:


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Dev.OM.User, Dev.OM"
table="USER">
<id name="USER_ID"
type="int">
<generator class="assigned" />
</id>
<property name="FName"
type="String"/>
<property name="LName"
type="String"/>
</class>
</hibernate-mapping>

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

Configuration cfg = new Configuration();
cfg.AddAssembly("Dev.OM");

VS is not registering my instantiation of configuration. I have included
the NHibernate.dll to the project as well as my direct statements for
NHibernate and NHibernate.cfg . Is there something simple that I am missing. I get the ever popular invalid token when i try to Add the Assembly with the Mapping file and concrete class.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 08, 2008 2:40 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
The config file should be hibernate.cfg.xml I think and you have to flag it as "Embedded Resource" in VS. If that not's the problem, post your configuration and the exact error you get.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Cannot compile my Mapping File
PostPosted: Sat Mar 08, 2008 9:49 pm 
Newbie

Joined: Sat Mar 08, 2008 12:24 am
Posts: 4
Hibernate version:
1.21 GA

Web.config:
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">Nhibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.provider">Nhibernate.Connection.DriverConnectionProvider</property>
<property name="connection.connection_string">Server=(local)/SQLEXPRESS; initial catalog=user;</property>
<mapping assembly="Dev.OM"/>
</session-factory>
</hibernate-configuration>


Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Dev.OM.User, Dev.OM"
table="USER">
<id name="USER_ID"
type="int">
<generator class="assigned" />
</id>
<property name="FName"
type="String"/>
<property name="LName"
type="String"/>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
ISession session = NHibernateHelper.GetCurrentSession();
ITransaction tx = session.BeginTransaction();

User usr = new User();
usr.FName = "Joe";
usr.LName = "Schmo";

session.Save(usr);
tx.Commit();
NHibernateHelper.CloseSession();

Stack Trace:
Could not load type Nhibernate.Dialect.MsSql2005Dialect. Possible cause: no assembly name specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.TypeLoadException: Could not load type Nhibernate.Dialect.MsSql2005Dialect. Possible cause: no assembly name specified.

Source Error:

Line 11: static NHibernateHelper()
Line 12: {
Line 13: Configuration cfg = new Configuration().Configure();
Line 14: cfg.AddAssembly("Dev.OM");
Line 15: sessionFactory = cfg.BuildSessionFactory();


Source File: C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\Dev\Dev.OM\NHibernateHelper.cs Line: 13

Stack Trace:

[TypeLoadException: Could not load type Nhibernate.Dialect.MsSql2005Dialect. Possible cause: no assembly name specified.]
NHibernate.Util.ReflectHelper.TypeFromAssembly(AssemblyQualifiedTypeName name, Boolean throwOnError) +570
NHibernate.Util.ReflectHelper.ClassForName(String name) +55
NHibernate.Dialect.Dialect.InstantiateDialect(String dialectName) +51

[HibernateException: Could not instantiate dialect class Nhibernate.Dialect.MsSql2005Dialect]
NHibernate.Dialect.Dialect.InstantiateDialect(String dialectName) +163
NHibernate.Dialect.Dialect.GetDialect(IDictionary props) +148
NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) +57

[MappingException: Could not compile the mapping document: Dev.OM.User.hbm.xml]
NHibernate.Cfg.Configuration.LogAndThrow(MappingException me) +62
NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) +205
NHibernate.Cfg.Configuration.ProcessMappingsQueue() +38
NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument document) +42
NHibernate.Cfg.Configuration.AddXmlReader(XmlTextReader hbmReader, String name) +60
NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) +149
NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly) +248
NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly) +172
NHibernate.Cfg.Configuration.AddAssembly(String assemblyName) +182
NHibernate.Cfg.Configuration.DoConfigure(XmlDocument doc) +1199
NHibernate.Cfg.Configuration.Configure(XmlTextReader reader) +494
NHibernate.Cfg.Configuration.Configure(XmlNode node) +106
NHibernate.Cfg.Configuration.Configure() +74
NHibernateHelper..cctor() in C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\Dev\Dev.OM\NHibernateHelper.cs:13

[TypeInitializationException: The type initializer for 'NHibernateHelper' threw an exception.]
NHibernateHelper.GetCurrentSession() in C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\Dev\Dev.OM\NHibernateHelper.cs:30
_Default.Page_Load(Object sender, EventArgs e) in c:\Documents and Settings\Owner\My Documents\Visual Studio 2005\WebSites\Dev\Default.aspx.cs:18
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 09, 2008 3:23 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
The dialect should be "NHibernate.xxx" not "Nhibernate.xxx" !

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 09, 2008 3:26 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Have a look at the documentation:

http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/session-configuration.html#configuration-optional

"System-level properties can only be set manually by setting static properties of NHibernate.Cfg.Environment class or be defined in the <nhibernate> section of the application configuration file. These properties cannot be set using Configuration.SetProperties or be defined in the <hibernate-configuration> section of the application configuration file"

According to that, "dialect" cannot be specified in the way you do it.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 09, 2008 2:40 pm 
Newbie

Joined: Sat Mar 08, 2008 12:24 am
Posts: 4
Thanks wolli for your help so far...

Currently I have all the properties set up in the web config. Should I define the properties in the Assembly where my mappings and concrete classes are (Dev.OM)? If so would I need to put it in the App.config or just make a new xml file called NHibernate.cfg.xml and set the properties there. If the latter is true how do I load the settings?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 09, 2008 3:52 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
The typo didn't cause the problem ? Since the exception contained your misspelled dialect, I assume, that hibernate reads it anyway.

If you use a hibernate.cfg.xml, you have to flag it as "Embedded Ressource". Then hibernate will load it when you build your session factory.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 4:26 pm 
Newbie

Joined: Sat Mar 08, 2008 12:24 am
Posts: 4
Thanks for all your help Wolli how do I rate the replies? I can now insert, update and delete an object. But... my update updates the record i get by ID but it changes part of one field that is not part of the update. When I do the update it cuts the time off my timestamp of a field that is unaffected. Would this have to do with my transactions/sessions? No exceptions are thrown and I do not have Log4net set up yet. Is there a way to see the SQL that is sent?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 10:38 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You can set hibernate.show_sql=true in your configuration. That will show you the sql in the output.

I don't believe your update problem has anything to do with transaction or session. It has more likely something to do with your mapping or your code. Post mappings, classes and your code between loading the object an flushing the session.

Perhaps better to start a new thread for that.

_________________
--Wolfgang


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