# org.hibernate.AnnotationException: Unable to create unique key constraint while making more than one column

**URL:** <https://discourse.hibernate.org/t/org-hibernate-annotationexception-unable-to-create-unique-key-constraint-while-making-more-than-one-column/3479>\
**Category:** Hibernate ORM\
**Created:** [November 27, 2019, 11:09am UTC](https://discourse.hibernate.org/t/org-hibernate-annotationexception-unable-to-create-unique-key-constraint-while-making-more-than-one-column/3479 "2019-11-27T11:09:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhiraj07](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/dhiraj07/32/175_2.png) [@dhiraj07](https://discourse.hibernate.org/u/dhiraj07)\
**Post date:** [November 27, 2019, 11:09am UTC](https://discourse.hibernate.org/t/org-hibernate-annotationexception-unable-to-create-unique-key-constraint-while-making-more-than-one-column/3479/1 "2019-11-27T11:09:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![djarnis73](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/djarnis73/32/645_2.png) [@djarnis73](https://discourse.hibernate.org/u/djarnis73)\
**Post date:** [December 4, 2019, 9:32am UTC](https://discourse.hibernate.org/t/org-hibernate-annotationexception-unable-to-create-unique-key-constraint-while-making-more-than-one-column/3479/2 "2019-12-04T09:32:57Z")

</div>

I believe I struggled with this as well at some point and my solution was to use the “java” names.

As in `columnNames = {"playStartDay", "group" }` I believe the naming strategy is applied to the names used in the annotation.

Best regards Jens
