Hoops, sorry. The first example without annotation (private List<OrderLine> orderLines) produces a jointable called Order_OrderLine. The question is more how to not have a join table but a foreign key in OrderLine ?
2006/11/3, Antonio Goncalves <antonio.mailing@gmail.com>:Hi.I'm using GlassFish V2b24. I want to model a unidirectional OneToMany relationship between the two classes Order -----*-> OrderLine. A bi-directional relation works fine (addind a Order attribut into OrderLine), but I can't make the unidirectional work. Here is the code (simplified) :public class Order implements Serializable {
@Id @GeneratedValue
private Long id;
@ManyToOne @JoinColumn(name = "customer_fk", nullable = false)
private Customer customer;
private List<OrderLine> orderLines;
}public class OrderLine implements Serializable {
@Id @GeneratedValue
private Long id;
private Integer quantity;
@OneToOne(optional = false) @JoinColumn(name = "item_fk")
private Item item;
}That works at deployment and creates both tables but without any foreign key or a join table between them. When I add the @OneToMany annotation :
@OneToMany
private List<OrderLine> orderLines;It produces the following error at deployment :
org.apache.derby.client.am.SqlException: 'ORDER_FK' is not a column in table or VTI 'DBUSER.T_ORDER_LINE'.
And I would love to have a foreign key order_fk. I've also read that for a unidirectional I need to use the mappedBy attribute. But this is what happens
@OneToMany(mappedBy = "order")
private List<OrderLine> orderLines;Exception Description: The attribute [orderLines] in entity class [class com.yaps.petstore.entity.order.Order] has a mappedBy value of [order] which does not exist in its owning entity class [class com.yaps.petstore.entity.order.OrderLine ]. If the owning entity class is a @MappedSuperclass, this is invalid, and your attribute should reference the correct subclass.
What am I doing wrong ? Does anybody have an idea ?
Thanks,
Antonio