org.hibernate.AnnotationException: Unable to create unique key constraint - if column not found

Description

Entity:

Embeddable containing the affected column:

Exception occurs:

The exception itself is about missing column or naming strategy (which is another problem), but this bug refers to incorrect usage of "unique constraint", since the code never specifies unique=true, so it should be just a regular index. i.e. "Unable to create index" would be an accurate error message.

An additional issue (which may be another bug?) is that hibernate.ddl-auto is not set, so I'm wondering why would Hibernate want to create anything?

Environment

Spring Boot 1.4.0, Hibernate Spatial, PostgreSQL 9.5

Activity

Show:
Chris Cranford
July 30, 2016, 6:37 PM

You could enable info logging for org.hibernate.cfg.Environment ? There should be a message that Hibernate prints at bootstrap with all the configuration parameters it has been provided with, both from the hibernate.properties file, any default settings, or those supplied as a part of the EntityManagerFactory/SessionFactory bootstrapping process. It'd be interesting to know if you do see hibernate.hbm2ddl.auto specified.

Hendy I.
July 30, 2016, 6:45 PM
Edited

Problem is, it doesn't show anything...

application.properties (Spring Boot) :

(BTW: the hibernate-spatial/PostgisDialect has no effect whatsoever on this issue, I've tried turning it off, same behavior. This behavior occurs both in hibernate 5.0.9 and 5.2.1)

I'm afraid this ticket conflates the "unique key constraint" message with the "DDL" issue. I have no problem discussing both issue in this ticket but I hope it's clear that these are 2 separate issues (although without the DDL issue, I wouldn't have known the unique key constraint message issue).

Chris Cranford
July 30, 2016, 6:49 PM

Would it be possible to provide me a very simplistic test case app that replicates the problem?

Chris Cranford
August 2, 2016, 4:02 AM
Edited

I created my own spring-boot 1.4.0.RELEASE based application that used Hibernate 5.2.1.Final and couldn't reproduce the automatic creation of the indices as you described. Looking at the auto configuration logic inside spring boot, it seems this should only happen if you're using Derby, H2, or HSQL as I indicated above. The only other way this would happen is if there is some other outside influence on that particular hibernate setting.

But in doing so, I did identify an issue with PostgreSQL82Dialect (which also includes PostgrisDialect). You can read more about it, HHH-11016.

Unless you provide evidence otherwise, I'll proceed with making the exception message change as part of 5.2.2 this week and close this issue.

Chris Cranford
August 2, 2016, 9:46 PM

, I'm going to go ahead and apply my PR. Feel free to open a specific issue regarding the index creation problem if you can provide a test case.

Assignee

Chris Cranford

Reporter

Hendy I.

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Minor
Configure