• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Non numeric id mapping

 
Piotr Cierny
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a table with primary key which is a string.
How should mapping for such id look like?

<id name="name" column="name" type="string">
</id>

Is this enough or the id element should have <generator class="assigned"/>?
If so what does it mean that id is assigned, hibernate won`t insert id when creating a new object or maybe it won`t insert it to join table fk column and i have to do it my self.

Any help will be appreciated
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may have a problem with doing autogeneration, but that's not needed. If you can figure out how to generate the values yourself, just set the id in code, and do a save. The data will be saved appropriately. Are you getting any exceptions when you do such a thing?

-Cameron McKenzie
 
Piotr Cierny
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don`t have any exceptions because i`m on DB project stage.

So you`re saying that if have dictionary table say with two unique names (john, mike) and name column is my PK i don`t have to worry about inserting and updating becasue hibernate will insert the value of name taken form Bean to the PK column in my DB and to FK column (if there are any joins)

I this right?
 
Ramesh Srinivasan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Piotr Cierny:
I don`t have any exceptions because i`m on DB project stage.

So you`re saying that if have dictionary table say with two unique names (john, mike) and name column is my PK i don`t have to worry about inserting and updating becasue hibernate will insert the value of name taken form Bean to the PK column in my DB and to FK column (if there are any joins)

I this right?


Hi Cierny,

Why dont you use an ID of your name. I meant to say instead of having name String as PK you could have ID as PK. Is there any specific reason behind?

Ramesh
 
Piotr Cierny
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well i use dictionary table where every name value is unique and so this column can be used as primary key.
Besides if i use id as pk, column name will be repeated many times (when joining) what i think is not a very nice solution.

I still don`t know if hibernate will assign my string name value taken from bean to pk and if there are any joins to fk column (I`m rookie in hibernate). But if so than i don`t have to worry about generation because the only way to add new name is through WEB UI.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic