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
448 views
in Technique[技术] by (71.8m points)

java - Adding Schema name to entity in Spring data?

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...
See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

The @Table annotation provides the schema attribute:

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

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

...