java - hibernate - disables MySQLIntegrityConstraintViolationException -
java - hibernate - disables MySQLIntegrityConstraintViolationException -
is there way disable during insert/delete?
situation: have masterdb , library1db , library2db.
library1db , library2db 2 separate database has same schema because each library must have own database. have masterdb, aggregated version of info in libraries (library1db , library2db), still taking note of respective ids , mapping them library id.
here's construction of book model in masterdb?
book.java
@id @generatedvalue(strategy = generationtype.auto) private long masterid; @column private long id; @column private string title; @onetomany(cascade = cascadetype.all, fetch = fetchtype.lazy, mappedby = "book") private list<bookcoverhistory> bookcoverhistory; @manytoone(fetch = fetchtype.lazy) @joincolumn(name = "library_id") private library library;
this , well.
however in bookcoverhistory when i'm inserting data, i'm getting exception below.
bookcoverhistory.java
@id @generatedvalue(strategy = generationtype.auto) private long masterid; @column private long id; @manytoone(fetch = fetchtype.lazy) @joincolumn(name = "book_id") private book book; @column private string desc;
here's exception:
com.mysql.jdbc.exceptions.jdbc4.mysqlintegrityconstraintviolationexception: cannot add together or update kid row: foreign key constraint fails (`master_db`.`book_cover_history`, constraint `fk_10ggatm9ptqayo4naj23329rc` foreign key (`book_id`) references `book` (`master_id`))
so thought, disable constraints since i'm not specific them i'm aggregating info on libraries masterdb , not crud operations manually through syncing process.
you cannot disable constraint checking in hibernate, because hibernate shows errror thrown database.
you using same database connection inserting data. said have multiple dbs, need connection/session other database. if table defined, can insert without reference other books.
also, you'd need remove joins, since tables in same column. need bring together books , covers manually, if tables not share same database (and session).
java hibernate
Comments
Post a Comment