com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'CONTACTID' in 'field list'

eclipselink, jpa, mysql, spring

Solution

This usually occurs when you have mixed access type - having some annotations on properties and some on fields. Unless you override the access type, the provider is left to pick the access type for the entity based on what annotation it finds first, and so will ignore others. A good explaination of the access type is given here

Make sure that all your annotations are consistent through out the model.

Problem

I use EclipseLink to generate all my objects from MySQL, I have a field called `CONTACT_ID`. When I am trying to `em.persist(contact)`, I got an errer msg saying "`Unknown column 'CONTACTID'`". I searched through out my project and database, I don't have any column named `CONTACTID`. Somehow JPA removes the '_' in this column name. I am sure it's something really stupid, I just can't find out why. Here is my db design: User.java: ``` @EmbeddedId private UserPK id; private int score; //bi-directional many-to-one association to CmnContact @ManyToOne(fetch=FetchType.LAZY, cascade = CascadeType.ALL) @JoinColumn (name="CONTACT_ID") private CmnContact cmnContact; //bi-directional many-to-one association to Login @ManyToOne(fetch=FetchType.LAZY, cascade = CascadeType.ALL) @JoinColumn (name="LOGIN_ID") private Login login; ``` CmnContact.java: ``` @Id @JoinColumn(name="CONTACT_ID") private String contactId; //bi-directional many-to-one association to User @OneToMany(mappedBy="cmnContact") private List<User> users; ``` UserPK.java: ``` @Column(name="USER_ID") private UUID userId; @Column(name="CONTACT_ID", insertable=false, updatable=false) private UUID contactId; @Column(name="LOGIN_ID", insertable=false, updatable=false) private UUID loginId; ```

Original source

Related problems