samedi 25 juillet 2015

One to many table creation

I'm really new to Hibernate and this is my first app which is enterprise level. I'm stuck at one to many mapping. I did the mapping whole day but it doesn't give to correct table structure for me.

Here is the ER diagram I want to map ER Diagram

These are the Classes

Feed Class

@Entity
public class Feed {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
private String name;
private long quantity;
//With getters and setters
}

Feed Order Details Class

@Entity
public class FeedOrderDetail {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private double unitPrice;
private long quantity;

@OneToMany(cascade=CascadeType.MERGE)
@JoinColumn(name="feed_id")
private List<Feed> feed = new ArrayList<Feed>();

//Getters and Setters
}

after deploying app I get the following table structure

Table Structure

My problems are why feed_id is in Feed table? Should I add same feed every time I add a feed order detail? (it isn't a good idea)

I can achieve this by moving @OneToMany annotation and attributes to Feed table. but if I move it to Feed class how can I represent feed order details in JSP pages?

I'm using spring with this project also.

Aucun commentaire:

Enregistrer un commentaire