Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Non numeric id mapping

 
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
 
author and cow tipper
Posts: 5000
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?
 
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.
 
Well don't expect me to do the dishes! This ad has been cleaned for your convenience:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic