java - MySQLIntegrityConstraintViolationException on mapping @onetomany unidirectional mapping in hibernate -


i have 2 entities having unidirectional onetomany relationship these are

entity 1

public class jeans implements serializable {  @id @generatedvalue private int id;  @onetomany private list<colorandpattern>  colorandpatterns;  } 

entity 2

public class colorandpattern implements serializable {  @id @generatedvalue private int id;  private string description;  private string background;  private boolean enabled;  private int gender;  } 

i using hibernates default mapping result in generation of seperate table named "jeans+colorandpattern" onetomany mapping

bussiness method

i using hibernate's save method persist entity

@override     public int addjeans(jeans jeans) {      sessionfactory.getcurrentsession().save(jeans);     return jeans.getid();     } 

however when try add same colorandpattern different jeans getiing

com.mysql.jdbc.exceptions.jdbc4.mysqlintegrityconstraintviolationexception: duplicate entry '1' key 'uk_la26iue5ciou6o4dy2gc23tlo'

i have gone through hibernates documentation , find out in such cases hibernate added unique constraint child entity didnt want how override behaviour or there better way


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -