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...
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.
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.
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.
The @Table
annotation provides the schema
attribute:
@Table(name = "Dog", schema = "Vet")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With