Two tables One class
Problem: Two tables One class can anyone help me map declaratively Order with hibernate in order.hbm.xml ??
I have One pojo Order with following properties userId comes from object User and Map includes Item name and quantity of Item in basket
Order
private int userId
private int orderId
private Map<It开发者_JAVA技巧em, Integer> basket
Item
private int itemId
private String name
private double price
User
private int userId
private String userName
private String password
private String firstName
private String lastName
my tables summary is below Order ID is primary key in UserOrder and foreign key in Orders in orders Order ID and and Item ID are composite Primary key
Tables
UserOrder
---------
USERID NUMBER
ORDERID NUMBER PRIMARY KEY
ORDERS
-------
ORDERID NUMBER
ITEMID NUMBER
QUANTITY NUMBER
A User can place many Orders; an Order can contain one or more Items. So it's standard one-to-many relationships in Hibernate.
I wouldn't recommend using a Map to hold Item; use a List or Set. You already have quantity as an attribute on Item.
精彩评论