I Want to make unique of a foreign key and another column.
I tried the code.
@Entity
@Table(name = "group_playlist", uniqueConstraints = @UniqueConstraint(name = "unique_range",
columnNames = {
"play_start_day", "group_id" }))
public class GroupPlaylist extends JsonType {
/**
*
*/
private static final long serialVersionUID = -982336326147846219L;
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@Fetch(FetchMode.JOIN)
@JoinColumn(name = "group_id")
private Group group;
private Long groupCompanyId;
private String playlistTitle;
private Date playStartDay;
private Date playEndDay;
private Integer totalSongs;
private BooleanEnum isDefaultPlaylist;
@Type(type = "json")
@Column(columnDefinition = "json")
private Map<Long, PlayListFilter> playlistFilterParams = new LinkedHashMap<>();
}
But this code throwing exception:
org.hibernate.AnnotationException: Unable to create unique key constraint (play_start_day,
group_id) on table group_playlist: database column 'play_start_day' not found. Make sure that you
use the correct column name which depends on the naming strategy in use (it may not be the same
as the property name in the entity, especially for relational types)
And I have DB with column names in the snake case.
like play_start_day, group_id