You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have an Oracle database, and a table, which is owned by TERRABYTE user. The thing is that the connection to Oracle database is obtained not by the TERRABYTE user, but by another user. Therefore we have to explicitly specify not only the Table we want to insert to, but also the owner, like:
INSERT TERRABYTE.PARKING_PLACE(......
instead of simply doing
INSERT PARKING_PLACE(....
Is there a way to do it in spring-data-jdbc? Seems @Table does not provide such functionality.
Ok that's great, but I there is a problem. I mean, it does not work along with @Table annotation, consider the example:
@Data
@Table("PARKING_PLACE")
public class ParkingPlace {
@Id
@Column("Id")
private long id;
@Column("location_code")
private int locationCode;
@Column("occupier_id")
private int occupierId;
@Column("purchase")
private LocalDateTime purchaseDate;
}
And also, if we register the bean like this:
@Bean
NamingStrategy namingStrategy() {
return new NamingStrategy() {
@Override
public String getSchema() {
return "TERRABYTE";
}
};
}
We should
a) allow to specify a schema in the @Table annotation
b) if none is given, use the schema returned by the NamingStrategy with the name given via @Table.
I think yes, this would be a great improvement. I can take a loot at it. Can you please take a loot at #1047. It will be great to merge it in near future also. Thank you in advance.
Activity
schauder commentedon Nov 24, 2021
You can register a custom
NamingStrategywhich implementsgetSchemato return the schema name.mipo256 commentedon Nov 24, 2021
Ok that's great, but I there is a problem. I mean, it does not work along with
@Tableannotation, consider the example:And also, if we register the bean like this:
The generated query will look like the following:
Executing prepared SQL statement [INSERT INTO "PARKING_PLACE" ("location_code", "occupier_id", "purchase") VALUES (?, ?, ?)]Whereas if I remove
@Tablewith qualified name, the generated query includes the schema (Oracle user in our case):Executing prepared SQL statement [INSERT INTO "TERRABYTE"."PARKING_PLACE" ("location_code", "occupier_id", "purchase") VALUES (?, ?, ?)]But I cannot remove the
@Tablein my case, nor I can rename the entity. I assume that this is a bugschauder commentedon Nov 24, 2021
You are correct, this is a bug.
We should
a) allow to specify a schema in the
@Tableannotationb) if none is given, use the schema returned by the
NamingStrategywith the name given via@Table.mipo256 commentedon Nov 24, 2021
I think yes, this would be a great improvement. I can take a loot at it. Can you please take a loot at #1047. It will be great to merge it in near future also. Thank you in advance.
Polishing.
Support specification of a schema in Column annotations.