Why @Column annotation ignored when connecting to MySQL via OpenJPA?
Issue
-
Follow below steps to replicate the issue.
-
Create
JPA projectusingOpenJPA2(JPA moduleofJBoss EAP 6.3.0 GA) asJPA Provider. -
Use
org.hibernate.cfg.ImprovedNamingStrategyas naming strategy to generate and map entities. -
Specify different property name which should not match to the field name of that particular entity which is mapped with respective table.
-
Following is code snippet to replicate this issue.
-
@Column(name="attr_id")
private Long attrId;
@Column(name="company_id")
private String companyId;
@Column(name="email")
private String email;
@Column(name="usr_name")
private String userName;
//Below is property type which does not follow org.hibernate.cfg.ImprovedNamingStrategy strategy.
@Column(name="date_created")
private Date creationDate;
- Try to access
date_createdfield from above entity and you will face below exception.
Caused by: <openjpa-2.3.0-r422266:1540826 fatal user error> org.apache.openjpa.persistence.ArgumentException: "com.redhat.model.user.creationDate" declares column "date_created", but this column does not exist in table "USER".
at org.apache.openjpa.jdbc.meta.MappingInfo.mergeColumn(MappingInfo.java:692) [openjpa-2.3.0.jar:2.3.0]
at org.apache.openjpa.jdbc.meta.MappingInfo.createColumns(MappingInfo.java:593) [openjpa-2.3.0.jar:2.3.0]
Environment
- MySQL connector
- 5.1.29
- Java
- 7u51
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6.x
- OpenJPA
- 2.3.0
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
