• 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Hibernate sequence exposed as property

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the application that I currently work on generators (of type sequence) are used to create the IDs for all of our objects, so I somewhat understand how this works.

What I need for a feature I'm adding is a integer value that is incremented during a particular point of execution in the program. I was thinking that a sequence would be perfect for this. Has anyone ever done this before? I can't seem to figure out how to expose (read and set) the sequence value.

Rich
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you can make your mapping to the attribute be a "formula" attribute which can be "SELECT mySequence.nextVal FROM Dual" in Oracle for example.

Mark
 
Richard Everhart
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark.

Now my problem is creating the Hibernate configuration file. I've created the file but my sequence has no id column, which means that I can't provide an ID element withing my class element. Without the id element an XML parsing exception occurs during initialization.

Anyone have any ideas how to get around this. composite-id can also be supplied but I haven't looked into that yet.

Rich
 
Richard Everhart
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the solution. Pretty easy really.



The id is just the column holding the sequence name. This seemed to make things happy. I'm using postgresql by the way.

Rich
 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Richard Everhart:
I found the solution. Pretty easy really.



The id is just the column holding the sequence name. This seemed to make things happy. I'm using postgresql by the way.

Rich



Yeah, I was about to ask what DB you were using.

Sounds like you got what you were looking for, congrats.

Mark
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to add doubt which I am having..

can I mention sequence name in property tag also?

<property name="count" column="seq_name" >

here seq_name will generate next value for count so is it possible?
 
It means our mission is in jeapordy! Quick, read this tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic