aspose file tools*
The moose likes Object Relational Mapping and the fly likes Issue in inserting into DB using Hibernate, Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Issue in inserting into DB using Hibernate, Spring" Watch "Issue in inserting into DB using Hibernate, Spring" New topic
Author

Issue in inserting into DB using Hibernate, Spring

Mike Thomson
Ranch Hand

Joined: Nov 07, 2007
Posts: 115
I am setting up the enviornment for my project in Sturts with Spring and Hibernate and facing the below issue.
First, I am trying to add the bank details in the DB as below.
The flow executed properly, but when querying the table no records found.
For example:
I have added the bank details with bank code 4000 (primary) and it's executed and I can able to see the insert query in the console, but record is not inserted into DB.
But when I tried to insert the bank code again with 4000, I am getting duplication error.

I have give below the codings. Please help to advice.











Ram Para
Ranch Hand

Joined: Jul 09, 2008
Posts: 50
Did you find anything?

Because the bindings seems to be right

Can you try with some other DB.(Might be your database is corrupted.)


Ram Parashar
http://doinfinite.com
Gerardo Tasistro
Ranch Hand

Joined: Feb 08, 2005
Posts: 362
Mike Thomson wrote:
I have added the bank details with bank code 4000 (primary) and it's executed and I can able to see the insert query in the console, but record is not inserted into DB.
But when I tried to insert the bank code again with 4000, I am getting duplication error.


BankCode or BankId???

According to your comment bank code is the primary. According to the XML mapping BankId is your Id, bank code is just unique. Do you have other records in the database with bank code 4000??

Look into your table status and check the autoIncrement value. If something is being inserted that should update.

Another question. Why is the error code saying "could not insert: [com.mdd.web.pojo.Bank] " and your XML says:

<class catalog="mysql" name="com.mdd.web.persistance.bank.Bank" table="bank">

Seems like the xml you published does not correspond to the class that is generating the error when being inserted.
Mike Thomson
Ranch Hand

Joined: Nov 07, 2007
Posts: 115

BankCode or BankId???

According to your comment bank code is the primary. According to the XML mapping BankId is your Id, bank code is just unique. Do you have other records in the database with bank code 4000??

Look into your table status and check the autoIncrement value. If something is being inserted that should update.

Another question. Why is the error code saying "could not insert: [com.mdd.web.pojo.Bank] " and your XML says:

<class catalog="mysql" name="com.mdd.web.persistance.bank.Bank" table="bank">

Seems like the xml you published does not correspond to the class that is generating the error when being inserted.



1. Yes, Bank Id is primary and bank code is unique.
2. The table mysql.bank is empty. No record is there.
3. I have given the wrong class name, it should be com.mdd.web.pojo.Bank in Bank.hbm.xml file



I am not getting any errors/exception and I can able to see the insert query into the console, but the record is not in the table.However strangely If I try to give the same bank code, then duplication error, but records in that bank table. How come this error? Please help on this.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Issue in inserting into DB using Hibernate, Spring