Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Saving Data

 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to save Data into the database but the its not working i have hh.setFirstName("xxxxxx");
hh.setLastName("yyyyyy");
hh.setName("dodoododo");
hh.setPassword("trying");
hh.setRole("User");
and
Session g=HibernateSessionFactory.currentSession();
g.save(hh);

but when i looked in the SQL Generated i saw
insert into PointWare.dbo.Admin (Name, Password, [First Name], [Last Name], Role) values (?, ?, ?, ?, ?)
Pls does anyone have a suggestion as to why the values are not being inserted?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

but when i looked in the SQL Generated i saw
insert into PointWare.dbo.Admin (Name, Password, [First Name], [Last Name], Role) values (?, ?, ?, ?, ?)

That's fine. Hibernate uses PreparedStatements so that's how you should expect the SQL to look. Do the values get inserted in the database? If not, do you close/flush the session and commit the transaction (if it is running in one)?
 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not running in a transaction and I always close the session and No the values don't get inserted.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In which case there must be an exception thrown. What does that say?
 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
none whatsoever i Used

catch(HibernateException m){
m.printstacktrace();
}
catch(Exception t){
t.printstacktrace();
}
 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
none whatsoever i Used

catch(HibernateException m){
m.printstacktrace();
}
catch(Exception t){
t.printstacktrace();
}
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Session is being flushed/closed, there is no transaction to commit, Hibernate is issuing a SQL statement and there is no exception?! Very, very odd. Can you post your code? Not just snippets, but the code from where you open the session to where you close/flush it. Also which database are you using? And could you post your mapping?
[ June 27, 2006: Message edited by: Paul Sturrock ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic