This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue in inserting into DB using Hibernate, Spring

 
Mike Thomson
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you find anything?

Because the bindings seems to be right

Can you try with some other DB.(Might be your database is corrupted.)
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic