3

What kind of ID's are allowed in hibernate? int and long for sure! Can I use String or even something like a Map or a List?

eclipse
  • 2,831
  • 3
  • 26
  • 34
  • A Map or a List? You could (probably) do that if you created your own custom key, but I would recommend you study up on database design if you really think thats a good idea. – Perception Jan 22 '12 at 12:56

1 Answers1

4

You can create your own identifier, of any type.

Look at the reference documentation : http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/mapping.html#mapping-declaration-id

ndeverge
  • 21,378
  • 4
  • 56
  • 85
  • Well in the documentation it just says type="typename". Does that mean now i can just write type="LinkedList"????? How would that work then? – eclipse Jan 22 '12 at 13:09
  • No, you can't. Look at the paragraph "5.1.2.2. Identifier generator" – ndeverge Jan 22 '12 at 13:12
  • Sorry that I have to ask again. So if I have a class with one attribute which is a LinkedList I still need a secound attribute called ID which I will generate using a generator? Could you be a bit more specific please I am new to the subject. – eclipse Jan 22 '12 at 13:30
  • Hibernate forces you to have an id for every entity. If you use annotations, look at http://stackoverflow.com/questions/2011528/hibernate-auto-increment-id, else look at http://stackoverflow.com/questions/1838520/hibernate-problems-with-auto-increment-id-mysql-5 – ndeverge Jan 22 '12 at 13:36