Why @Column annotation ignored when connecting to MySQL via OpenJPA?

Solution Verified - Updated -

Issue

  • Follow below steps to replicate the issue.

    • Create JPA project using OpenJPA2 (JPA module of JBoss EAP 6.3.0 GA) as JPA Provider.

    • Use org.hibernate.cfg.ImprovedNamingStrategy as 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_created field 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, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content