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?
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.
In my case this code works, one physical table field name and one entity object member field name.
@Table(uniqueConstraints={@UniqueConstraint(columnNames = {"account_id" , "measureDate"})})
but this code doesn't work at all with same exception.
@Table(uniqueConstraints={@UniqueConstraint(columnNames = {"account_id" , "measure_date"})})
Someone reported this bug to hibernate. Check this. https://forum.hibernate.org/viewtopic.php?f=9&t=986581&view=next
I use
If any of constrained column anotated with @Column(name="...")
:
You need add @Column(name = "...")
to another constraining columns too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With