JPA: default column name mapping for @ManyToOne relations

Kdeveloper picture Kdeveloper · Oct 19, 2010 · Viewed 36.5k times · Source

When we have a class:

@Entity
Order implements Serializable {
    @Id
    private Integer id;
    ...
}

and:

@Entity
OrderLine implements Serializable {
    @Id
    private Integer id;

    @ManyToOne
    Order order;
    ...
}

What row name will the property order map to?

order_id, ORDER_ID or Order_id?

(ommiting the @JoinColumn(name='order_id') is deliberate)

Answer

Oscar Chan picture Oscar Chan · Oct 19, 2010

I might not understand your question. However, don't you need something like below?

@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="order_id", nullable=false)
Order order;

here are some examples