EdgeCase
EdgeCase

Reputation: 4827

JPA Naming Convention

I am new to ORM (EclipseLink), and am wondering what is the best practice in a case like this? I know that we're stuck with the legacy column names on existing tables, but what about new entities?

For example, do most people generate the underlying DB table using customer_id or customerid, in the case below? I like having them the same name, but it might look odd to our Oracle DBA.

Just want to go with the flow.

public class Invoice {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "invoice_id", unique = true, nullable = false)
    private long invoiceId;

    @Column(name = "customer_id", length = 25, nullable = false)
    private String customerId;
}

Upvotes: 1

Views: 965

Answers (1)

Blesson Jose
Blesson Jose

Reputation: 698

Like you, I would use customer_id for the actual column in db and for the entity field I would use camel casing - customerId.

When I did a research last time, I came to the conclusion that words in db column names should be better separated using underscore because some databases don't support case sensitive field names. So it will be harder to read without underscore in between.

Upvotes: 2

Related Questions