Here is an example  :

With Order / OrderPK / OrderLine (=> has a composite primary key with 2 foreign 
keys)


  | @Entity
  | @Table(name="ORDERS")
  | public class Order {
  | 
  |     private int id;
  |     
  |     private Date orderDate;
  | 
  |     @Id
  |     @GeneratedValue(strategy=GenerationType.AUTO)
  |     public int getId() {
  |             return id;
  |     }
  | 
  |     public void setId(int id) {
  |             this.id = id;
  |     }
  | 
  |     public Date getOrderDate() {
  |             return orderDate;
  |     }
  | 
  |     public void setOrderDate(Date orderDate) {
  |             this.orderDate = orderDate;
  |     }
  | }
  | 





  | 
  | @Entity
  | @IdClass(OrderLinePk.class)
  | public class OrderLine {
  | 
  |     private Product product;
  | 
  |     private Order order;
  |     
  |     private int quantity;
  | 
  |     public OrderLine() {
  |     }
  | 
  |     public int getQuantity() {
  |             return quantity;
  |     }
  | 
  |     public void setQuantity(int quantity) {
  |             this.quantity = quantity;
  |     }
  | 
  |     @ManyToOne
  |     @JoinColumn(name="orderId", insertable=false, updatable=false)
  |     public Order getOrder() {
  |             return order;
  |     }
  | 
  |     public void setOrder(Order order) {
  |             this.order = order;
  |     }
  | 
  |     @ManyToOne
  |     @JoinColumn(name="productId", insertable=false, updatable=false)
  |     public Product getProduct() {
  |             return product;
  |     }
  | 
  |     public void setProduct(Product product) {
  |             this.product = product;
  |     }
  |     
  |     @Id
  |     public int getProductId() {
  |             return getProduct().getId();
  |     }
  |     
  |     @Id
  |     public int getOrderId() {
  |             return getOrder().getId();
  |     }
  |     
  |     public void setOrderId(int orderId) {
  |             getOrder().setId(orderId);
  |     }
  |     
  |     public void setProductId(int productId) {
  |             getProduct().setId(productId);
  |     }
  |     
  | }
  | 
  | 
  | 



  | 
  | @Embeddable
  | public class OrderLinePk implements Serializable {
  | 
  |     private static final long serialVersionUID = 1L;
  | 
  |     private int orderId;
  | 
  |     private int productId;
  | 
  |     protected OrderLinePk() {
  |     }
  |     
  |     public OrderLinePk(int orderId, int productId) {
  |             this.orderId = orderId;
  |             this.productId = productId;
  |     }
  | 
  |     public int getOrderId() {
  |             return orderId;
  |     }
  | 
  |     public void setOrderId(int orderId) {
  |             this.orderId = orderId;
  |     }
  | 
  |     public int getProductId() {
  |             return productId;
  |     }
  | 
  |     public void setProductId(int productId) {
  |             this.productId = productId;
  |     }
  | 
  | }
  | 
  | 
  | 

Hope it would be useful.

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3941942#3941942

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3941942


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to