• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unknown Id.generator Hibernate exception

 
Pramod Kumar
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting this exeception when i m trying to generate sequence ids with oracle database.

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE ,generator="my_seq")
@Column(name = "USER_ID", unique = true, nullable = false, insertable = true, updatable = true, scale = 0)
public long getUserId() {
return this.UserId;
}

public void setUserId(long UserId) {
this.UserId = UserId;
}

I am getting this exception

javax.persistence.PersistenceException: org.hibernate.AnnotationException: Unknown Id.generator: my_seq

I have created sequence in oracle --> create sequence my_seq.
Any Idea?

Thanks,
 
Shailesh Kini
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ngpramod,

Not sure if you are compliant with the naming convention used at JavaRanch.

But... Here's what you are supposed to do.

You have declared your strategy to use Sequences, however you haven't told JPA which sequence it should be using.

You should add another annotation under @GeneratedValue...
@SequenceGenerator(name="my_seq" sequenceName="<actual seq name as it exists in oracle database>")

This should fix your problem.
 
Pramod Kumar
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shailesh Kini,

Thanks a lot, its working
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!