tags:

views:

212

answers:

2

The column and table names that JPA providers create when you're not using @Column tags and the like, are always capitalized. I think the JPA spec even says they should. But is there a specific technical reason, like backends that are case insensitive?

In other words, will my habit of always setting camelcased names with the name argument to the @Column annotation turn around and bite me one day?

(Note that I appreciate convention over configuration, but sometimes I just want to have my way.)

A: 

If the operating system where your database is running is case-sensitive, then the casing of table names must be correct.

In Linux, the following refer to different columns:

@Column(name="MY_TABLE")

@Column(name="my_table")

Kennet
A: 

Having underscore-separated names for database objects is a bit of a historical habit, mainly because database systems are often case-insensitive. In this situation, having a table name where the words all run together is rather unreadable (e.g. MYLONGTABLENAMEISNTVERYREADABLE). Using underscores is just a naming convention to make things easier to read, just like camel case is.

If you move from underscore-separated to camel case, you'll be OK, since JPA implementations are designed to work with case-sensitive as well as case-insensitive databases.

skaffman
By "are designed to work", do you mean, they'll automagically work around case.insensitive backends when I use names that require case-sensitivity to distinguish tables? Not that I ever had table names that were identical in all but letter case - I'd find that too confusing for humans anyway.
Hanno Fietz
I mean that JPA implementations (e.g. Hibernate) have "dialects" for each database system, and will behave accordingly. If you have two names identical but for case, the dialects should complain.
skaffman