java - Am I using a ManyToMany mapping in JPA properly? -


i working on school project, , goal make javaee application fictional pharmacy.

since 1 drug can cure 1 or many diseases , 1 disease can treated 1 or many drugs, figured @onetomany relation on drug side , @manytomany on disease side. have patient entity. patient may suffer 1 or many diseases, , 1 disease may afflict many patients. coded classes follows incompatible-mapping-exception between drug , disease classes when try generate tables entities. using glassfish server , derby connection in eclipse (everything well-configured, it's code issue). classes follows:

public class drug implements serializable{ @onetomany(targetentity = disease.class, mappedby = "cures_for_this_disease") private list<disease> diseases_cured_by_this_drug; //other fields such name, price , origin of drug }  public class disease implements serializable{ @manytomany(targetentity = drug.class) private list<drug> cures_for_this_disease; @manytomany(targetentity = patient.class) private list<patient> afflicted_patients; //other fields such name of disease etc. }  public class patient implements serializable{ @onetomany(targetentity = disease.class, mappedby = "afflictedpatients") private list<disease> current_diseases; //other fields such patient name, social sec. nubmer etc } 

what doing wrong?

you should have @manytomany annotation in drug , patient classes.

public class drug implements serializable{     @manytomany     private list<disease> diseases_cured_by_this_drug;  }  public class disease implements serializable{     @manytomany(mappedby="diseases_cured_by_this_drug")     private list<drug> cures_for_this_disease; } 

this should create join table between 2 corresponding tables.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -