Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...
like image 248
java123999 Avatar asked Apr 01 '16 11:04

java123999


People also ask

What is @entity annotation in spring?

The @Entity annotation specifies that the class is an entity and is mapped to a database table. The @Table annotation specifies the name of the database table to be used for mapping.

How do I connect multiple schemas in spring boot?

Until now with spring 4 and XML configuration I was able to only put the DB URL like: jdbc:mysql://180.179.57.114:3306/?zeroDateTimeBehavior=convertToNull and in the entity class specify the schema to use and thus able to connect to multiple schemas.

What is @table annotation in spring boot?

The @Table annotation allows you to specify the details of the table that will be used to persist the entity in the database. The @Table annotation provides four attributes, allowing you to override the name of the table, its catalog, and its schema, and enforce unique constraints on columns in the table.


1 Answers

The @Table annotation provides the schema attribute:

@Table(name = "Dog", schema = "Vet")
like image 122
Patrick Avatar answered Sep 28 '22 15:09

Patrick