Today I was struggling with WLS 10.3, Workshop 10.3, JPA and Hibernate to get an Entity persistent to a Database. I got the following error:
I used the following code (which was acutally generated by Workshop!):
As you can see from the error code the column name "email_internet" (as indicated by @Column) was not taken, but instead the "emailInternet" property was taken.
I could not find the problem, but the following helped. Move the JPA annotation above the private property, like this:
This solved my problem, but not sure if this is a Hibernate, JPA bug?
I used the following code (which was acutally generated by Workshop!):
@Entity() @Table(name="werknemers") public class Werknemer implements Serializable { //default serial version id, required for serializable classes. private static final long serialVersionUID = 1L; @Id private String persNummer; private String emailInternet; public Werknemer() { } @Basic() @Column(name="email_internet", nullable=false, length=128) public String getEmailInternet() { return this.emailInternet; } public void setEmailInternet(String emailInternet) { this.emailInternet = emailInternet; } }
As you can see from the error code the column name "email_internet" (as indicated by @Column) was not taken, but instead the "emailInternet" property was taken.
I could not find the problem, but the following helped. Move the JPA annotation above the private property, like this:
@Basic() @Column(name="email_internet", nullable=false, length=128) private String emailInternet;
This solved my problem, but not sure if this is a Hibernate, JPA bug?
Hi,
BeantwoordenVerwijderenThis is neither a bug in JPA nor in Hibernate.
There are 2 access types : property access (via "getters") and field access (i.e "attribute") ; but you can't mix both in the same entity (in this case, the specification states that the behavior is undefined).
Unless you explicitly specify the type by means of the javax.persistence.Access annotation. But the mix can be hard to debug... ;-)
--
Mat'