Forums Register Login

is ID tag in hibernate map.xml is compulsory?

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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
1
+Pie Number of slices to send: Send
 

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.

%
Tell me how it all turns out. Here is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 6648 times.
Similar Threads
Hibernate insert or select gives "Identifier of an instance altered"
How to represent a sequence in oracle in HQL
How could I map this if possible?
Problem using Hibernate Native Statement
Persisting a class to two tables with Hibernate
simple hibernate excercise
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:58:56.