Adding Schema name to entity in Spring data?

跟風遠走 提交于 2020-01-03 19:31:13

问题


I am getting an error when using an Oracle DB and Spring Data. The error is:

ORA-00942: table or view does not exist

The cause of this error is that the user I am connecting with does not have access to the tables in the schemas I wish to connect to.

I read that 2 fixes to this are to create synonyms in my database or to specify the schema that each entity/table belongs to.

I am going to try the Schema approach first. How do I do so?

My example entity below, a Dog in the Vet Schema:

@Entity
@Table(name = "Dog")
public class Dog
{
    @Id
    private String id;

    @Column(name = "NAME")
    private String name;

    @Column(name = "Owner")
    private String owner;

  //getters and setters etc...

回答1:


The @Table annotation provides the schema attribute:

@Table(name = "Dog", schema = "Vet")



回答2:


You must prefix your tables with the schema name and with a . inbetween them:

@Table(name = "VET.Dog")


来源:https://stackoverflow.com/questions/36355358/adding-schema-name-to-entity-in-spring-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!