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.  [ 15 posts ] 
Author Message
 Post subject: Please help - i'am new at nhibernate
PostPosted: Wed Sep 26, 2007 2:39 am 
Newbie

Joined: Tue Sep 25, 2007 6:21 am
Posts: 6
hello,

i have tested the "Hibernate Quick Start Guide" (http://www.hibernate.org/362.html).

but i get an exception in my testproject (with MSAccess), when i want to write the data with transaction.Commit();

ADOException: could not insert: [NHibernateTest.User#joe_cool][SQL: INSERT INTO users (Name, Password, EmailAddress, LastLogon, LogonId) VALUES (?, ?, ?, ?, ?)]

can anyone help?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 26, 2007 6:58 am 
Beginner
Beginner

Joined: Mon May 14, 2007 2:50 am
Posts: 22
Firs thing to do is this:
1. Get the sql that NHibernate is producing
2. Rund the sql manually against the database.

does insert succeed this way?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 26, 2007 8:14 am 
Newbie

Joined: Tue Sep 25, 2007 6:21 am
Posts: 6
hello DarkCloud,

thanks for answering.

i think this is the sql-statement, that nhibernate produces:
INSERT INTO users (Name, Password, EmailAddress, LastLogon, LogonId) VALUES (?, ?, ?, ?, ?)

the question is, why?

here my code (that is from the "quick start quide"):

// create a Configuration object...
Configuration cfg = new Configuration();
cfg.AddAssembly( "NHibernateTest" );

// create a session object...
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();

// create an user
User newUser = new User();
newUser.Id = "joe_cool";
newUser.UserName = "Joseph Cool";
newUser.Password = "abc123";
newUser.EmailAddress = "joe@cool.com";
newUser.LastLogon = DateTime.Now;

// Tell NHibernate that this object should be saved
session.Save( newUser );


// commit all of the changes to the DB and close the ISession
transaction.Commit();

// close this Session
session.Close();

an idea?

thank you


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 26, 2007 11:17 am 
Regular
Regular

Joined: Fri Jan 20, 2006 7:45 pm
Posts: 97
Location: San Antonio, TX
SiliconDream wrote:
hello DarkCloud,

thanks for answering.

i think this is the sql-statement, that nhibernate produces:
INSERT INTO users (Name, Password, EmailAddress, LastLogon, LogonId) VALUES (?, ?, ?, ?, ?)

the question is, why?



NHibernate uses prepared statements to interact with the database. You are looking at where the prepared statement is being generated, like so:
Code:
Building an IDbCommand object for the SqlString: INSERT INTO SAWS.WATERMETER_MODEL (MODELNO, SAWS_SIZE_CODE, SAWS_TYPE_CODE, SAWS_MFG_CODE, MFGKEY, WATERMETERTYPE_CODE, ID) VALUES (?, ?, ?, ?, ?, ?, ?)


If you look further down in the log file, you'll see where the actual insert takes place, like so:
Code:
INSERT INTO SAWS.WATERMETER_MODEL (MODELNO, SAWS_SIZE_CODE, SAWS_TYPE_CODE, SAWS_MFG_CODE, MFGKEY, WATERMETERTYPE_CODE, ID) VALUES (:p0, :p1, :p2, :p3, :p4, :p5, :p6); :p0 = '99-99-99', :p1 = '99', :p2 = '99', :p3 = '99', :p4 = '1326', :p5 = ' ', :p6 = '429'

Here you see there the actual insert takes place. This is the statement you would want to test directly against the DB. Does that help?

_________________
Dum spiro, spero
-------------------------------
Rate my post if it helps...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 27, 2007 6:52 am 
Newbie

Joined: Tue Sep 25, 2007 6:21 am
Posts: 6
hello jlockwood,

thanks for answering.

unfortunately i don't know, where i can find this log-file.

can you help?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 28, 2007 3:57 am 
Beginner
Beginner

Joined: Mon May 14, 2007 2:50 am
Posts: 22
Quote:
If you look further down in the log file, you'll see where the actual insert takes place, like so:
Code:
INSERT INTO SAWS.WATERMETER_MODEL (MODELNO, SAWS_SIZE_CODE, SAWS_TYPE_CODE, SAWS_MFG_CODE, MFGKEY, WATERMETERTYPE_CODE, ID) VALUES (:p0, :p1, :p2, :p3, :p4, :p5, :p6); :p0 = '99-99-99', :p1 = '99', :p2 = '99', :p3 = '99', :p4 = '1326', :p5 = ' ', :p6 = '429'



Hey! I've never seen those in my log files :)
I use log4net and Castle.ActiveRecord.

Did i forgot to tell nhibernate to log sql explicitly, or what?
:)[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 28, 2007 3:58 am 
Beginner
Beginner

Joined: Mon May 14, 2007 2:50 am
Posts: 22
SiliconDream wrote:
hello jlockwood,

thanks for answering.

unfortunately i don't know, where i can find this log-file.
can you help?
thanks


Logging is managed by log4net library.

you should read log4net documentation to see how to set up your logging, if you did not do it already

http://logging.apache.org/log4net/


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 28, 2007 3:23 pm 
Beginner
Beginner

Joined: Tue Sep 14, 2004 1:03 pm
Posts: 33
Location: Calgary, Alberta Canada
To show the SQL NHibernate is producing, set show_sql to true.

Code:
<entry key="hibernate.show_sql"
               value="true" />


When you run your unit test the SQL NHibernate is producing will display to the console. (even it you didn't setup log4net)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 08, 2007 4:46 am 
Newbie

Joined: Tue Sep 25, 2007 6:21 am
Posts: 6
hi padlewski,

thanks for answering.

okay, this is what nhibernate produces:

NHibernate: INSERT INTO users (Name, Password, EmailAddress, LastLogon, LogonId) VALUES (?, ?, ?, ?, ?); p0 = ‘Joseph Cool’, p1 = ’abc123’, p2 = ‘joe@cool.com”, p3= ‘ 08.10.2007 10:36:32’, p4 = ‘joe_cool’

somebody has an idea why this does not work at MSAccess?

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 10, 2007 11:16 am 
Regular
Regular

Joined: Fri Jan 20, 2006 7:45 pm
Posts: 97
Location: San Antonio, TX
SiliconDream wrote:
hi padlewski,

thanks for answering.

okay, this is what nhibernate produces:

NHibernate: INSERT INTO users (Name, Password, EmailAddress, LastLogon, LogonId) VALUES (?, ?, ?, ?, ?); p0 = ‘Joseph Cool’, p1 = ’abc123’, p2 = ‘joe@cool.com”, p3= ‘ 08.10.2007 10:36:32’, p4 = ‘joe_cool’

somebody has an idea why this does not work at MSAccess?

Thank you.


Can you show us your config file? NHibernate does support access and the dialect should give access what it needs to work.

_________________
Dum spiro, spero
-------------------------------
Rate my post if it helps...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 16, 2007 10:58 am 
Newbie

Joined: Sun Oct 07, 2007 10:47 am
Posts: 4
Hi,
I'm trying to do the same example (QUICK START) and I got the same problem.

Did you find solution for that ?

Thanks for your help.
Ben.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 16, 2007 1:16 pm 
Regular
Regular

Joined: Fri Jan 20, 2006 7:45 pm
Posts: 97
Location: San Antonio, TX
You might want to create a new posting. It's hard to determine what "same problem" means. The original post addressed confusion over the SQL generated by NHibernate.

_________________
Dum spiro, spero
-------------------------------
Rate my post if it helps...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 17, 2007 11:43 am 
Newbie

Joined: Sun Oct 07, 2007 10:47 am
Posts: 4
Hello,

you're right,
By "same problem" I meant this:

ADOException: could not insert: [NHibernateTest.User#joe_cool][SQL: INSERT INTO users (Name, Password, EmailAddress, LastLogon, LogonId) VALUES (?, ?, ?, ?, ?)]

Thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 22, 2007 4:58 am 
Newbie

Joined: Tue Sep 25, 2007 6:21 am
Posts: 6
Hello bmb,

i've find the problem by myself: It doesn't work with MSAccess2000, even if you use the NHibernate.JetDriver.

If you do the test with MSSQLServer, the sample works fine!

I hope this helps!

greetings


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 27, 2007 9:43 am 
Newbie

Joined: Sun Oct 07, 2007 10:47 am
Posts: 4
Hello ,

Thank you very much SiliconDream,

My problem was not with DB Server cause I used MSSQLServer, but it was with using mapping fields' format (in HBM file) which is different from the data filed format (in DB)...

Hope that helps,
thanks again.
bmb.


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