Announcement Announcement Module
Collapse
No announcement yet.
how to set explicit id instead of generated id ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to set explicit id instead of generated id ?

    I am using Spring with Hibernate. I am really pleased with Spring, but I have hit a hurdle. I have a bean defined with a generated ID field, e.g.

    .
    .
    .
    @Id
    @GeneratedValue(generator="system-uuid")
    @GenericGenerator(name="system-uuid", strategy = "uuid")
    public String getOrganisationID()
    {
    return organisationID;
    }
    .
    .
    .


    Everything works fine with the ids being generated automatically, but there are some instances where I want to use a specific id value instead of the generated value. Any attempt to set the value before calling HibernateTemplate.save() is ignored and the generator replaces my value with the generated value. I agree that this is correct behaviour, but I wonder is there any (easy) way to override the generated value on save ?

    many thanks

  • #2
    I was able to overcome this by instead using a HQL insert statement, which bypasses the auto key generation.

    Comment

    Working...
    X