Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

naming conventions when doing O/R mapping

I am mapping my database tables to my java objects. Generally I name my tables in the plural form in that a table holding books information is called BOOKS. The java object represents however one book and should be called Book. Similarly for AUTHORS/Author etc.

On the other hand, its kind of simplistic to give the same to the domain object and the table.

Is there some kind of naming convention that people follow? I guess this applies to applications in general and not just while doing O/R mapping.

like image 482
Kapsh Avatar asked Feb 20 '26 11:02

Kapsh


2 Answers

Your initial thoughts are spot on.

Objects should be singular, as each object is individual.

Tables should be plural, as the table contains all.

Check out the naming conventions built into Ruby on Rails, they're relevant.

like image 183
Bevan Avatar answered Feb 22 '26 00:02

Bevan


We use singular for table names and for OM classes. It makes more sense, to me, to say

person.last_name

than

people.last_name,

whether I'm writing SQL or Java (where, of course, it would be person.lastName, but you get the point).

like image 44
Carl Manaster Avatar answered Feb 22 '26 00:02

Carl Manaster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!