java - @ManyToMany using @JoinTable -


i have following 2 entities , 1 join table:

entity:

@entity @table(name = "person") public class parent {  @onetoone(mappedby="person", cascade= cascadetype.all)  private reader reader;  //more fields , getters , setters , of course @id..... } 

and entity:

@entity @table(name="reader") public class reader{   @id  @column(name= "reader_id")  @generatedvalue(generator="gen")    @genericgenerator(name="gen", strategy="foreign", parameters=@parameter(name="property", value="person"))    private long readerid;   @onetoone    @primarykeyjoincolumn    private person person;   @manytomany(fetch = fetchtype.eager)  @jointable(name = "reader_books", joincolumns={@joincolumn(name="reader_id")}, inversejoincolumns={@joincolumn(name="book_id")})  private list<books> books;  //more fields , getters , setters } 

and have join table in data base named "reader_books" consisted 2 columns - readerid , bookid - both primary key pair, , each of columns foreign key corresponding table.

a few details:

  • i have defined "manytomany" relationship in reader.java, meaning reader can have many books ,and books can reused in other readers ( example reader can have same books other readers). can see reader id , person id same - defined "onetoone" relationship - works fine.
  • in books entity class didn't add reference or stated relationship because understood don't need to.

the problem:

when add person , set reader field several books, works , database filled right values.(a person,reader , join tables inserted new rows)

the problem when delete person instance or reader instance , the books instance not null(books assigned reader). hibernate stuck , not throwing execption. but when books instance null (didnt assign books reader) deletion successfull.

i think might wrong "manytomany" , because when join table empty deletion successful.

what wrong in implementation?

edited: found out hibernate gets stuck if list empty, think wrong "onetoone" anottation, maybe missed out something

there no problem in implementation. use pl/sql developer , didn't notice acquired lock on 1 of tables :|. when tried delete record, hibernate got stuck , reason didn't throw error.

any way, implementation correct.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -