Issue
I have the following entity:
@Entity
@Table(name = "campaign_content", uniqueConstraints = @UniqueConstraint(columnNames = { "campaignContentId", "campaignId", "fieldTag" }))
public class CampaignContent implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "campaign_content_id")
private Integer campaignContentId;
@Column(name = "field_content")
private String fieldContent;
@Column(name = "campaign_id")
private Integer campaignId;
@Column(name = "field_tag")
private String fieldTag;
With getter and setter.
However I get:
caused by: org.hibernate.AnnotationException: Unable to create unique key constraint (campaignContentId, campaignId, fieldTag) on table campaign_content: campaignContentId, campaignId, fieldTag not found
What is wrong?
Solution
The name of the column is campaign_content_id
, not campaignContentId
. Same thing for the other columns, of course. The columnNames
attribute expects an array of ... column names. Not an array of Java field or property names.
Answered By - JB Nizet
Answer Checked By - Cary Denson (JavaFixing Admin)