Skip to content
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

Cannot use SimpleJdbcInsert with catalog name #32124

Closed
jesudornenkrone opened this issue Jan 25, 2024 · 4 comments
Closed

Cannot use SimpleJdbcInsert with catalog name #32124

jesudornenkrone opened this issue Jan 25, 2024 · 4 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@jesudornenkrone
Copy link

jesudornenkrone commented Jan 25, 2024

I use spring 6.1.3 with MSSQL.

My code:

orderInsert = new SimpleJdbcInsert(jdbcTemplate).withTableName("tbOrder").withCatalogName("CamWeso").withSchemaName("dbo").usingGeneratedKeyColumns("OrderID");

orderId = orderInsert.executeAndReturnKey(newOrderParams);

If I use this code, it generate the following SQL:

INSERT INTO dbo.tbOrder (CustomerID, OrderNumber, OrderTypeID, StatusID, DivisionID, AssigneeID, ReceivedAt, CreatedBy, CreatedAt, OwnerID, IsPortationOrder, WorkflowStateIndex) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

But I expected it to be:

INSERT INTO CamWeso.dbo.tbOrder ...

I took a look at TableMetaDataContext.createInsertString which uses schemaName and tableName but doesn't use catalogName.

If I use SimpleJdbcCall with withCatalogName, it works.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 25, 2024
@jhoeller jhoeller added the in: data Issues in data modules (jdbc, orm, oxm, tx) label Jan 25, 2024
@snicoll
Copy link
Member

snicoll commented Jan 26, 2024

Thanks for the report. We usually just use the schema and catalog names for metadata lookup, but I can see how that looks inconsistent. However, it's far from being obvious as some database may not support specifying a catalog this way.

Why is the catalog necessary for MSSQL server here?

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Jan 26, 2024
@jesudornenkrone
Copy link
Author

We have one SQL Server instance but with two separate databases (designed as different catalogs).
One is the applications database and one is a legacy database, we just want to keep in sync, until we get rid of it.

I could create two JDBC connections and use them, but that would involve distributed transactions, wouldn't it? So using the same JDBC connection to write into both catalogs, seemed like a "smart/simple" idea.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jan 26, 2024
@snicoll snicoll added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Jan 26, 2024
@snicoll snicoll added this to the 6.1.x milestone Jan 26, 2024
@snicoll snicoll self-assigned this Jan 26, 2024
@sbrannen sbrannen changed the title Cannot use SimpleJdbcInsert with catalog name Cannot use SimpleJdbcInsert with catalog name Jan 26, 2024
@snicoll snicoll modified the milestones: 6.1.x, 6.1.4 Jan 26, 2024
@snicoll
Copy link
Member

snicoll commented Jan 26, 2024

That makes sense. If you get a chance to test 6.1.4-SNAPSHOT available from repo.spring.io/snapshots shortly, that would be very much appreciated.

@jesudornenkrone
Copy link
Author

Thank you very much, I tested with spring-jdbc-6.1.4-20240129.153252-63.jar and it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants