spring boot hibernate query invalid user error

前端 未结 1 1657
野性不改
野性不改 2021-01-24 02:34

Hi I am new to Spring Boot. I try to connect to Oracle and list related records. My code worked in a stub environment, that is without connecting to a db. When I tried to connec

1条回答
  •  离开以前
    2021-01-24 03:28

    It seems that the problem is following:

    Because of this property:

    spring.jpa.properties.hibernate.hbm2ddl.auto = update
    

    And the fact that the Posts entity has been changed to reference the User, Hibernate tries to add a foreign key constraint:

    alter table posts add constraint FK6xvn0811tkyo3nfjk2xvqx6ns foreign key (author_id) references users
    

    But gets this error:

    ORA-02268: referenced table does not have a primary key
    

    Not sure why hibernate does not add a primary key to this table as the @Id annotation is clearly there.

    Try to add a primary key constraint manually to the Users.id column:

    ALTER TABLE users
     ADD CONSTRAINT users_pk PRIMARY KEY (id);
    

    Update

    The problem might with the Post.data mapping as you are using it in the order by clause.

    The doc says:

    This annotation must be specified for persistent fields or properties of type java.util.Date and java.util.Calendar. It may only be specified for fields or properties of these types.

    As you are using java.util.Date, then you need to add this:

    @Temporal(TemporalType.DATE)
    private Date date = new Date();
    

    0 讨论(0)
提交回复
热议问题