This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Conventions for name of ID-Field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Conventions for name of ID-Field" Watch "Conventions for name of ID-Field" New topic
Author

Conventions for name of ID-Field

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
When using this:

@Id
private Integer idPk;

then the field name "IDPK" is generated instead of "ID_PK"


So I have to use this:

@Id @Column(name = "ID_PK")
private Integer idPk;

to generate the fieldname "ID_PK".


I have thought, the conventions for defining the ID name is using the id with underscore continued with the first upper case of the property name. JPA should use this convention. Am I right?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What makes you think that is, or should be, the convention? I think "id" should come at the end--makes a lot more sense to me.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

I agree with David, while an underscore separator may be a convention it is not a standard. Some databases will treat an underscore as a wildcard character for white space so it can be problematic to use.

Also, personally, I think ID_PK is tautologous anyway. PK == ID, do why not name your identifying attribute "ID"?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
Hello both,

why not name your identifying attribute "ID"



This is a good suggestion. I renamed it.

Thanks.



 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Conventions for name of ID-Field
 
Similar Threads
Map multiple properties as @Id properties Problem
is it the correct mapping?
Input in a Nested table
call constructor from super-enum
java.lang.Reflection throwing error when using (String)field.get(new String());