• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Oracle sequences and JPA

 
Mateusz Moroz
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic