I tried several variations but none worked for me. The annotated mappings did not take place (i.e. mapped fields not populated by Hibernate). I knew I am doing something wrong or lack thereof some essentials. If I may run this by you, please help point out what I need to do to make this work.
I have 4 Classes: Business, Category, Consumer, PurchasedItem.
POJO Class Business:
Code:
@Configurable
@Entity
public class Business {
@Id
@NotNull
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "bus_id")
private Long busId;
public long getBusId() {
return busId;
}
public void setBusId(long busId) {
this.busId = busId;
}
@NotNull
@OneToMany(targetEntity=PurchasedItem.class, cascade = CascadeType.ALL)
@JoinColumn(name="bus_id", unique=true)
private List<PurchasedItem> purItems;
@NotNull
@ManyToOne(targetEntity = Consumer.class)
@JoinColumn (name="con_id", updatable=false,insertable=false)
private Consumer consumer;
@NotNull
@ManyToOne(targetEntity = Category.class)
@JoinColumn (name="cat_id", updatable=false, insertable=false)
private Category category;
@NotEmpty
@Size(max = 50)
@Column(name = "bus_na")
private String busNa;....
POJO Class Category:
Code:
@Configurable
@Entity
public class Category {
@Id
@NotNull
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "cat_id")
private Long catId;
public long getCatId() {
return this.catId;
}
public void setCatId(long catId) {
this.catId = catId;
}
@NotNull
@OneToMany(targetEntity=Business.class, cascade = CascadeType.ALL)
@JoinColumn(name="cat_id", unique=true)
private List<Business> businesses;
@NotNull
@OneToMany(targetEntity=PurchasedItem.class, cascade = CascadeType.ALL)
@JoinColumn(name="cat_id", unique=true)
private List<PurchasedItem> purItems;
@NotNull
@ManyToOne(targetEntity = Consumer.class)
@JoinColumn (name="con_id", updatable=false, insertable=false)
private Consumer consumer;
@NotNull
@Size(max = 50)
@Column(name = "cat_name")
private String catName;.....
POJO Class Consumer:
Code:
@Configurable
@Entity
public class Consumer {
@Id
@NotNull
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "con_id")
private Long conId;
public long getConId() {
return conId;
}
public void setConId(long conId) {
this.conId = conId;
}
@NotNull
@OneToMany(targetEntity=PurchasedItem.class, cascade = CascadeType.ALL)
@JoinColumn(name="con_id", unique=true)
private List<PurchasedItem> purItems;
@NotNull
@OneToMany(targetEntity=Category.class, cascade = CascadeType.ALL)
@JoinColumn(name="con_id", unique=true)
private List<Category> categories;
@NotNull
@OneToMany(targetEntity=Business.class, cascade = CascadeType.ALL)
@JoinColumn(name="con_id", unique=true)
private List<Business> businesses;
@Size(max = 50)
@Column(name = "first_name")
private String firstName;.....
POJO Class PurchasedItem:
Code:
@Configurable
@Entity
public class PurchasedItem {
@Id
@NotNull
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "pur_id")
private Long purId;
public long getPurId() {
return this.purId;
}
public void setPurId(long purId) {
this.purId = purId;
}
@NotNull
@ManyToOne(targetEntity = Business.class)
@JoinColumn (name="bus_id", updatable=false, insertable=false)
private Business business;
@NotNull
@ManyToOne(targetEntity = Consumer.class)
@JoinColumn (name="con_id", updatable=false, insertable=false)
private Consumer consumer;
@NotNull
@ManyToOne(targetEntity = Category.class)
@JoinColumn (name="cat_id", updatable=false, insertable=false)
private Category category;
@NotNull
@Column(name = "cat_id")
private long catId;.........
After I created new rows for each class, none of the JoinColummn(s) specified under @ManyToOne or @OneToMany was populated with mapped data. E.g.
Table: Category
cat_id: 1
cat_name: Parks
con_id: NULL
Any help will be greatly appreciated.