java - eclipselink doesn't care about foreign key constraint, but the DBMS does -


i have issue jpa , relation manytomany. use inheritance strategy both sides of relation. jpa doesn't take account foreign key constraints, mysql when use workbensh delete characters bound movie example.

i don't understand how jpa can pass through constraints.

the first class hierarchy :

@entity @discriminatorcolumn(name = "typeoeuvre",discriminatortype =  discriminatortype.integer) @table(name="oeuvre")  public abstract class etyoeuvre extends etyabstract implements  itcompositeinfo,comparable<etyoeuvre> {      @manytomany(cascade ={ cascadetype.persist},fetch = fetchtype.eager)     @jointable(name="oeuvres_characters", joincolumns =                @joincolumn(name="oeuvres_id"),inversejoincolumns =                @joincolumn(name="characters_id"))     @orderby("last_name,first_name asc")     protected list<etycharacter> characters  = new                                   linkedlist<etycharacter>();  }  @mappedsuperclass  public class etyoeuvrecinematographic extends etyoeuvre {  }  @entity @discriminatorvalue("1")   public class etyserietv extends etyoeuvrecinematographic {  } 

and second class hierarchy

@entity @discriminatorcolumn(name = "typehuman",discriminatortype =  public abstract class etyhuman extends etyabstract implements  comparable<etyhuman>{  }   @entity @discriminatorvalue("0") public class etycharacter extends etyhuman {      @manytomany(mappedby = "characters",cascade = cascadetype.persist,fetch                  = fetchtype.eager)     private list<etyoeuvre> oeuvres; } 

and dll code join table

create table `oeuvres_characters` (   `characters_id` int(11) not null,   `oeuvres_id` int(11) not null,   primary key (`characters_id`,`oeuvres_id`),   key `fk_oeuvres_characters_oeuvres_id` (`oeuvres_id`),   constraint `fk_oeuvres_characters_characters_id` foreign key   (`characters_id`) references `human` (`id`),   constraint `fk_oeuvres_characters_oeuvres_id` foreign key (`oeuvres_id`)  references `oeuvre` (`id`) ) engine=innodb default charset=utf8; oeuvres_characters 

the classes use in code etycharacter , instance etyserietv.

thanks :)

edit.

this sql generated when delete character :

  delete oeuvres_characters ((characters_id = ?) , (oeuvres_id    = ?))     bind => [76, 1]]]   delete human ((id = ?) , (version = ?))    bind => [76, 1]]] 

you can see deletes join_table references before. i'd preffer foreign key constraint eiter ^^.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -