I have 4 classes - Category, Consumer, Business, Document. They all have ManyToMany relationships. From all that I had read and tried and using petclinic as a template, I decided to map them with OneToMany and ManyToOne.
They do not work. I am new and I could be doing this totally wrong. Please give me some guidence.
I did not see any mapping data generated.
Code:
public class Document {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
public long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
@ManyToOne(targetEntity = Business.class)
@JoinColumn
private Business business;
@ManyToOne(targetEntity = Consumer.class)
@JoinColumn
private Consumer consumer;
@ManyToOne(targetEntity = Category.class)
@JoinColumn
private Category category;
@NotNull
@Column(name = "cou_id")
private long couId;
.....
Code:
public class Business {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
@OneToMany(cascade = CascadeType.ALL, mappedBy = "business")
private List<Document> documents = new ArrayList<Document>();
@ManyToOne(targetEntity = Consumer.class)
@JoinColumn
private Consumer consumer;
@ManyToOne(targetEntity = Category.class)
@JoinColumn
private Category category;
@NotNull
@Column(name="bus_id")
private long busId;
.....
Code:
public class Category {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "id")
private Long id;
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
@OneToMany(cascade = CascadeType.ALL, mappedBy = "category")
private List<Business> businesses = new ArrayList<Business>();
@OneToMany(cascade = CascadeType.ALL, mappedBy = "category")
private List<Document> documents = new ArrayList<Document>();
@ManyToOne(targetEntity = Consumer.class)
@JoinColumn
private Consumer consumer;
@Column(name = "cat_id")
private long catId;
....
Code:
public class Consumer {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
public long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@OneToMany(cascade = CascadeType.ALL, mappedBy = "consumer")
private List<Document> documents = new ArrayList<Document>();
@OneToMany(cascade = CascadeType.ALL, mappedBy = "consumer")
private List<Category> categories = new ArrayList<Category>();
@OneToMany(cascade = CascadeType.ALL, mappedBy = "consumer")
private List<Business> businesses = new ArrayList<Business>();
@NotNull
@Column(name = "con_id")
private long conId;
.....
Looking forward to any ideas and suggestions. Many Thanks.