This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Hibernate not inserting new record on SQL Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate not inserting new record on SQL Server" Watch "Hibernate not inserting new record on SQL Server" New topic
Author

Hibernate not inserting new record on SQL Server

Fernando Margueirat
Ranch Hand

Joined: Jun 07, 2004
Posts: 33
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

Joined: Apr 25, 2010
Posts: 532

You are not beginning a transaction.. After beginning, you need to commit also..
Fernando Margueirat
Ranch Hand

Joined: Jun 07, 2004
Posts: 33
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

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Fernando Margueirat
Ranch Hand

Joined: Jun 07, 2004
Posts: 33
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate not inserting new record on SQL Server