• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate not inserting new record on SQL Server

 
Fernando Margueirat
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone

I have tried Hibernate in the past for a couple of pilot projects but I'm a total newbie. I am trying to do some basic testing/configuration for a new project I am working on. My configuration is:

MS SQL Server 2008 R2
Eclipse Helios (3.6.2)
Hibernate 3.6.4

I've created a simple table



a simple class



my hibernate.cfg.xml



and the company.hbm.xml mapping file



then I run this simple Java app to test it



I don't get any errors, and I can see the correct SQL statement in the console

Hibernate: insert into t_company_test (company_name) values (?)


but no records are inserted in the database. I did a debug with the profiler and found that it executes the following



Any ideas of what am I missing or doing wrong?

Thanks

Fernando Margueirat
 
Prasad Krishnegowda
Ranch Hand
Posts: 671
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not beginning a transaction.. After beginning, you need to commit also..
 
Fernando Margueirat
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank a lot for you quick reply. That was the problem. I guess the tutorial I was using was not very good.

Fernando Margueirat
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Watch out, there are a lot of very poor tutorials out there. Hibernate's documentation is a better source - it's example covers the need for a transaction.
 
Fernando Margueirat
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:Watch out, there are a lot of very poor tutorials out there. Hibernate's documentation is a better source - it's example covers the need for a transaction.


Thanks, I learned my lesson the hard way .

Fernando Margueirat
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic