Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

postgresql - Hibernate "Unable to create unique key constraint" "database column 'counter', 'plage' not found"

I'm upgrading from Hibernate 4.x to 5.4. I have a postgresql 12 database.

When I start my application I get the following error:

Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unable to create unique key constraint (counter, day) on table CountDay: database column 'counter', '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)

I've seen other people having similar problems, but none of the solutions proposed there have worked for me.

My entity is simple :

@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"counter", "day"}))
@Entity
public class CounterDay {

    @Id
    @GeneratedValue
    private Long id;

    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    @JoinColumn(nullable = false)
    private Counter counter;

    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    @JoinColumn(nullable = false)
    private Day day;

    private Integer value;

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    public Counter getCounter() {
        return counter;
    }

    public void setCounter(Counter counter) {
        this.counter = counter;
    }

    public Day getDay() {
        return day;
    }

    public void setDay(Day day) {
        this.day = day;
    }

    public Integer getValue() {
        return value;
    }

    public void setValue(Integer value) {
        this.value = value;
    }
}

Both columns exist on my table counter_day, both are fully lowercase. The application worked without issue before upgrading to hibernate 5.X, so there must be something I am missing, and I see nothing in the upgrade guide.

Thanks in advance, any help would be appreciated.

question from:https://stackoverflow.com/questions/65890042/hibernate-unable-to-create-unique-key-constraint-database-column-counter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...