Insert Unique Rows into Database Tables Using Java, Hibernate -
i don't know asked or not. don't find anyone. (anyway not required project. when working database , hibernate had doubt , got time ask here. have not tried far going ask here)
suppose have table in database. want insert data table, unique rows.
how can possible?
from, this qestion, think, can insert unique rows databse.
so in java, using preparedstatement
, can able pass same query insert rows if row unique in table?
if possible, error/exception, java throw?
if not possible, best way so?
and how if using hibernate? how can same?
if passing bean class object save fields, how can check unique rows?
also how perform same list of objects?
hope understood situation.
so in java, using preparedstatement , can able pass same query insert rows if row unique in table?
if have set unique constraints fields in table, fail inserting duplicates.
if possible, error/exception, java throw?
your database raise error; :
duplicate entry 'xxxx' key 'whatever'
hopefully java application bring error database in way or another...
if passing bean class object save fields, how can check unique rows?
also how perform same list of objects?
if manipulating beans override equals()
, use java.util.set
instead of list
when inserting multiple rows.
anyway, @muel said: "it's better enforce uniqueness @ database level not application level." never corrupted data in database. however, easy override equals
in beans , check if don't have 2 (or more) objects identical.
Comments
Post a Comment