Skip to content

Specify Oracle user during DML operations #1099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mipo256 opened this issue Nov 24, 2021 · 4 comments
Closed

Specify Oracle user during DML operations #1099

mipo256 opened this issue Nov 24, 2021 · 4 comments
Labels
type: bug A general bug

Comments

@mipo256
Copy link
Contributor

mipo256 commented Nov 24, 2021

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 24, 2021
@schauder
Copy link
Contributor

You can register a custom NamingStrategy which implements getSchema to return the schema name.

@mipo256
Copy link
Contributor Author

mipo256 commented Nov 24, 2021

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";
            }
        };
    }

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 @Table with 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 @Table in my case, nor I can rename the entity. I assume that this is a bug

@schauder
Copy link
Contributor

You are correct, this is a bug.

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.

@schauder schauder added the type: bug A general bug label Nov 24, 2021
@mipo256
Copy link
Contributor Author

mipo256 commented 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.

@schauder schauder removed the status: waiting-for-triage An issue we've not yet triaged label Nov 25, 2021
schauder added a commit that referenced this issue Dec 7, 2021
Removed jetbrains annotation.
Removed attempt to cache annotation lookup.
Those lookups are already cached and obtaining them in the constructor causes overhead when they aren't requested at all.
Limit the use of Optional.

See #1099
Original pull request #1108
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants