I created an entity class with int @Id field (property exactly so I put annotation before "get" methods). It worked fine. Then, I thought that for my project it would be better to have an Integer Primry Key property instead of int and I tried to change it. And now I see that this causes a problem.
Changing field type goes well. But changing returning type in "get" method (into Integer) or changing internal parameter (explicit) in "set" method causes that my Eclipse IDE can't recognize primary key field. I get warning mark at @Entity annotation with tip "The entity has no primary key attribute defined"
Code looks like this:
If I remove Integer types from methods the Eclipse warning disappears.
But during deployment server throws Exceptions for that JPA entity class.
What is wrong with taht Integer type?
I can't find in documentation statement that Integer can't be used for primary key field.
I dont see a problem with the way you entity primary key is structured. The only constraint is that the primary key should be serializable and Integer definitely is.
This should work. Eclipse could be an ide local issue. Please provide what errors you are facing during deployment.
Also what JPA implementation you are using?
Joined: Feb 05, 2012
I don't get any errors during deployment (in the first case of code that I submitted) because I receive warning in Eclipse window while the code is written. It is the basic Eclipse check of the code - small icon of yellow bulb with red circle and white cross. I am usually using demployment on JBoss server merged to the Eclipse (the JPA provider is a native provider from JBoss 6.1). This warning doesn't allow me to deploy the appliaction on the server through Eclipse.
Right now I have done some check. I exported this whole project to EAR file and deployed it manually on the server and it works. I should have done it earlier : ) but changing PK type from Integer into int seemed for me faster solution than looking for a cause of the problem.
So the problem is Eclipse.