Reputation: 1
I'm .Net programmer but this time I'm working on Java project and I'm encountering some difficulties. This java project isn't mine, it was developed by other developer and it uses Hibernate.
When I run the Ant builder I receive this error:
9: error: annotation type not applicable to this kind of declaration
@SequenceGenerator( name="companynameSequence" , sequenceName="COMPANYNAME_SEQUENCE" , allocationSize=1 )
^
This annotation is in a file called package-info.java. The content of this file is just these few lines of code:
@SequenceGenerator( name="companynameSequence" , sequenceName="COMPANYNAME_SEQUENCE" , allocationSize=1 )
package com.companyname.application.model;
import javax.persistence.SequenceGenerator;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.TypeDef;
import org.jasypt.hibernate.type.EncryptedStringType;
If I remove that annotation the project compiles successfully but I have have a runtime error:
Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown Id.generator: companynameSequence
I'm using Eclipse Juno and JRE 1.7
Can you help me ?
Thank you
Upvotes: 0
Views: 1503
Reputation: 115
i am just running into this issue when migrating from 1.6 to 1.8. The problem here was that @javax.persistence.SequenceGenerator only targets @Target({ TYPE, METHOD, FIELD }), but not the packages. It was a bug until java 1.7 that annotations were not being handled properly. I dont know what the fix is, but I am looking for it.
Upvotes: 0
Reputation: 6208
You need to write something like this :
//different annotations
class className{
@Id
@SequenceGenerator(sequenceName = "COMPANYNAME_SEQUENCE", name = "companynameSequence")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="companynameSequence")
@Column(name="ID", nullable=false, unique=true)
private int id;
//other fields and methods
}
or this :
//different annotations
class className{
@Id
@SequenceGenerator(sequenceName = "COMPANYNAME_SEQUENCE", name = "companynameSequence")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="companynameSequence")
@Column(name="ID", nullable=false, unique=true)
public int getId(){};
//other fields and methods
}
this is only example and field names may differ from mine.
and read this post about identifiers and generators
Upvotes: 1
Reputation: 507
Annotations should not affect run-time behavior. Therefore, I would suggest commenting the annotation out and fixing the bug. I can't explain, however, the intent of the annotation or why it would throw an error.
Upvotes: 0