• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Oracle sequences and JPA

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm new to JavaRanch and I have a problem with saving object to database through EJB. I have a table, that has fields:
ID (where value is normally generated from sequence) and
YEAR_SEQ_NUMBER (which is sequence-generated value - every year its initial value is reset).

The problem is, that while the field ID works fine, the system does not give the value to YEAR_SEQ_NUMBER saying:


The way I'm trying to map:


I tried to put also the @Id annotation but the server claimed


Is it possible to give number to id automatically from a sequence, so it corresponds to:


?

Regards
 
Mateusz Moroz
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I solved the problem by writing a before insert trigger, that fills the field:



Although this is not elegant solution.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its also not a solution you should need. Which JPA implementation are you using?
 
Mateusz Moroz
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using EJB 3.0, so to make my question concrete, let's talk in the dialect of EJB3
 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic