• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is ID tag in hibernate map.xml is compulsory?

 
yamini nadella
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in many books I saw hibernate mapping xml having tag like

<id name="id" column="uid" type="long">
<generator class="native"/>
</id>

is "id" is a primary key? then what is generator class? how to represent multiple fields as primary key?

what if there is no primary key in a table?

is generator means this ID value is get generated automatically? What if I dont want to get ID generated automatically, I may assign value explicitly?

it is looking like hibernate is bit complex to understand?
 
Paul Clapham
Sheriff
Posts: 21554
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Hibernate is a bit complex to understand. I am fairly certain your questions are answered in the reference manual (which sits on my desk at work). You can download it in PDF or HTML from this page:

http://www.hibernate.org/5.html
 
Michael Duffy
Ranch Hand
Posts: 163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is "id" is a primary key?


Yes, in this case it is.

then what is generator class? how to represent multiple fields as primary key?


Generator is the way the database automatically increments the key. In Oracle, it's a sequence. In Microsoft SQL server, it's an identity column. In MySQL, it's auto_increment.

what if there is no primary key in a table?


Every table must have a primary key, or you've violated first normal form. What good is a table without one?

is generator means this ID value is get generated automatically?


Yes.

What if I dont want to get ID generated automatically, I may assign value explicitly?


I believe you have the option to handle it yourself, but I can't see why you'd want to.

it is looking like hibernate is bit complex to understand?


Yes, indeed.

%
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic