Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Conventions for name of ID-Field

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"?

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello both,

why not name your identifying attribute "ID"



This is a good suggestion. I renamed it.

Thanks.



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic