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

how hibernate cover the problem of duplication data ?

 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, i would like to ask how hinerate to detect duplication of data ?

for example, i use the following to save


due to using <generator class="increment"/> in mapping file, it does save the records by increment the id, in my case, only id column is unique but other column in db with have same, of course this cause by the way i set the data into object,

but let say i make my program save the data in dynamic way which means the data based on user actions, but how we make sure the data is not duplicate in database? so that when we query database, it won't give many records with same data ..is there anyway to control this ?
[ October 28, 2005: Message edited by: Nakata kokuyo ]
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To avoid adding additional rows, you'll need to query the database to find any objects that match the one you are about to save.

Hibernate's Query By Example makes this pretty easy.
 
Vinnie Jenks
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scott is correct. This is business-logic anyhow and does not belong in the database.
 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you , scott n vinnie
 
Ramakrishna Desu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
using unsaved-value parameter of the ID tag, check the value is null or not.
If Id value is null, using saveorupdate method it will insert the data.
If Id value is not null it will update the data.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic