Got 3 tables I need to connect.
Got my first project where I am making the database myself, while learning a new framework, which can be kinda confusing as I am not that well off when it come down to DBs.
I am using Spring 3.1.0.RELEASE and Hibernate 3.6.8.Final
I will name the most important attributes here, to give the general idea of what it is I am trying to achieve here.
Inventory (id, ItemName…)
Line_Items (WORKSHOP_ORDERS_Id, INVENTORY_Id, Quantity)
Workshop_Order (Id, WorkshopService, WorkshopNotes…)
This way I can hopefully have more than one item for each order, planning to hold one Line_Items for each different product in every order, linking it to the correct order by FKs.
I have tried different things with my annotations, my persistence.xml works, this is the only place in my code where there are any issues. I am 100% clueless on how to map this relation with annotations, so I am going to post my code here, even though it is no where near anything useful (but I may get some pointers).
import java.io.Serializable;
import javax.persistence.*;
@Entity
@Table(name = "LINE_ITEMS")
public class LineItems implements Serializable {
private static final long serialVersionUID = 2414994088922470197L;
public Long workshopOrderId;
public Long inventoryId;
public int quantity;
public Workshop workshop;
public Inventory inventory;
@OneToMany(mappedBy = "workshop",cascade = CascadeType.ALL)
@JoinColumn(name="WORKSHOP_ORDERS_Id", insertable = false, updatable = false, nullable = false)
public Workshop getWorkshop() {
return workshop;
}
@OneToMany(mappedBy = "inventory", cascade = CascadeType.ALL)
@JoinColumn(name="INVENTORY_Id", insertable = false, updatable = false, nullable = false)
public Inventory getInventory() {
return inventory;
}
public void setWorkshop(Workshop workshop) {
this.workshop = workshop;
}
public void setInventory(Inventory inventory) {
this.inventory = inventory;
}
@Id
@Column(name = "WORKSHOP_ORDERS_Id")
public Long getWorkshopOrderId() {
return workshopOrderId;
}
@Id
@Column(name = "INVENTORY_Id")
public Long getInventoryId() {
return inventoryId;
}
@Column(name = "Quantity")
public int getQuantity() {
return quantity;
}
public void setWorkshopOrderId(Long workshopOrderId) {
this.workshopOrderId = workshopOrderId;
}
public void setInventoryId(Long inventoryId) {
this.inventoryId = inventoryId;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
}
I have heard some talk about a bug in Hibernate, but not sure if this relates to my issue.
Basically what I need is not necessary the complete solution to the problem, but some idea of what I am doing and what I should do to correct it. I would love some assistance in both smart database design (regarding the tables I have shown, and the correct way to do it in Hibernate).
Any advice or help will be appreciated.
As per the description of tables you gave below are the relationships.
Currently in you entity you used OneToMany but one to many means one item can have many orders so order will become collection. SO that doesn’t seem right.
EDIT: EDITED RELATIONSHIP BETWEEN ITEM & WORKSHOP TO MANYTOONE INSTEAD OF ONETOONE AS PER COMMENT.