Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA: default column name mapping for @ManyToOne relations

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)

like image 845
Kdeveloper Avatar asked Oct 18 '10 22:10

Kdeveloper


People also ask

What is the default mechanism for representing one to many unidirectional relationships in JPA?

Unidirectional @OneToMany with @JoinColumn.

How does JPA define Many-To-One relationships?

In JPA a ManyToOne relationship is specified through the @ManyToOne annotation or the <many-to-one> element. A @ManyToOne annotation is typically accompanied by a @JoinColumn annotation. The @JoinColumn annotation specifies how the relationship should be mapped to (expressed in) the database.

How do I map OneToMany?

Create an entity class Student. java under com. javatpoint. mapping package that contains student id (s_id), student name (s_name) with @OneToMany annotation that contains Library class object of List type.


1 Answers

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

like image 83
Oscar Chan Avatar answered Sep 20 '22 05:09

Oscar Chan