Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does the identifier name have to be the same in all persistent classes ?

 
Gayatri Ganesh
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I am new to Hibernate. I was reading a .ppt on Hibernate.
It says under the topic "Database Identity in Hibernate"
"We add a new identifier property to the persistent classes"
-the name should always be the same for all classes eg :"id"

Does it mean that the identifier name should be the same in all persistent classes ? ie If you have a class like :

public class A {
private String id ;
}

public class B {
private String id ; //Should be named "id", not anything other than "id"
}

But in the B.hbm.xml file we have :

<hibernate-mapping >
<class name="B" table="B" >
<id name="id" ..../> (Here we specify the identifier, so can't we just put the name of the property of B.java which is the identifier
.............
</classs>

Can anyone please explain this ?

Thanks,
Gayatri
 
Loren Rosen
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, a bit about the oddities of English diction. Formally, "should" means "it's a good idea". If something is mandatory, you would use "must" instead of "should". But informally, people often use "should" where they mean "must" and it can be ambiguous.

In this case, though, "should" really does mean it's a good idea. It's a good thing to have a consistent convention for naming your identifier properties, and their corresponding database columns. You can be inconsistent, or use some complicated naming convention, but this is more important for adapting to legacy applications or databases, or adapting to existing corporate naming standards.
 
Gayatri Ganesh
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Loren.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic