2

I'm trying to define a unique constraint on a non-id field. The answer might seem obvious:

@Entity
@Table(uniqueConstraints=@UniqueConstraint(columnNames={"col1"}))
public class MyEntity { ... }

However, this is not working. I've checked the indexes in the collection through the mongo command line, but there is no trace of a unique index (only a _id_ index is being generated).

I have also tried with the @Index annotation without joy:

@Entity
@Table(indexes={ @Index(name = "myIndex", columnList="col1", unique = true) })
public class MyEntity { ... }

The @Column(unique = true) annotation doesn't have any effect either.

How can I get Hibernate OGM to create a unique index for this collection?

Thank you in advance,

Guillermo

  • does Hibernate OGM even claim to support unique constraints yet? I know DataNucleus JPA does, but not tried with Hibernate OGM – Neil Stockton Jun 17 '15 at 06:21
  • The Hibernate OGM documentation on the MongoDB dialect doesn't say a word about it (none that I could find, at least). However, if I introduce a wrong column name in either `columnNames` or `columnList` attributes, Hibernate OGM complains about it. Moreover, when I use `@UniqueContraint` or `@Column(unique = true)` annotations, the Hibernate OGM logs explicitly state that the field has `unique = true`. So there is some processing going on about this in the background... – Guillermo López Alejos Jun 17 '15 at 08:44

1 Answers1

2

Hibernate OGM does not yet consider this index/constraint meta-data for MongoDB. I've opened OGM-910 for tracking it.

Gunnar
  • 18,095
  • 1
  • 53
  • 73