Wednesday, 15 January 2014

hibernate - OneToMany CascadeType.ALL duplication -



hibernate - OneToMany CascadeType.ALL duplication -

i have 2 tables:

@entity @table(name = "consultas_sql") public class consultasql implements java.io.serializable { //... @onetomany(mappedby = "consultasql", orphanremoval = true, cascade = cascadetype.all) private list<parametrosql> parametros; //... }

and:

@entity @table(name = "parametros_sql") public class parametrosql implements java.io.serializable { //... @manytoone @joincolumn(name = "consulta_id", nullable = false, referencedcolumnname = "id") private consultasql consultasql; //... }

if create new object of type consultasql , insert 1 new object of type parametrosql, save succesful.

the problem when add together new parametrosql when editing consultasql, it's doubling parametrosql, in other words, saved duplicated in db.

i think have problem relationship onetomany. can help me?

sorry english.

thank all

i edited post add together commands insert , update. below codes:

public t insert(final t entity) { getentitymanager().persist(entity); homecoming entity; } public t update(t entity) { homecoming getentitymanager().merge(entity); }

thank you.

hibernate jpa one-to-many

No comments:

Post a Comment