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

Provide a way to get EntityRowMapper #1950

Open
VietAnh14 opened this issue Nov 25, 2024 · 3 comments
Open

Provide a way to get EntityRowMapper #1950

VietAnh14 opened this issue Nov 25, 2024 · 3 comments
Assignees
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged

Comments

@VietAnh14
Copy link

I want to reuse the EntityRowMapper to query using JdbcTemplate, currently I can't find an easy way to get the mapper for an entity class and have to copy paste code from DefaultDataAccessStrategy to create one. It would be nice if you could support this some how.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 25, 2024
@mp911de
Copy link
Member

mp911de commented Nov 25, 2024

Have you consulted the documentation?

Other than that, we do not accept RowMapper query method arguments.

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Nov 25, 2024
@VietAnh14
Copy link
Author

I think you miss understand me, I'm not using @Query annotation but using JdbcTemplate/NamedParameterJdbcTemplate to execute some query built at runtime. This query will return the entity so it's would be nice if I can reuse the EntityRowMapper class of spring data jdbc to map the result to entity.

Basically like this:

      var entityRowMapper = //Some how get spring data jdbc row mapper for entity class
      var user = namedParameterJdbcTemplate.queryForObject(
              "select * from users where id = :id", 
              Map.of("id", "0001"), 
              entityRowMapper
      );

@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 Nov 25, 2024
@lpraud
Copy link

lpraud commented Jan 4, 2025

For me, the advantage to use an EntityRowMapper is that it handles the Embedded.OnEmpty as I have Embedded object. That way the mapping is homogeneous with the usage of JdbcAggregateTemplate.

I've found this simple workaround for now (which maybe the same as @VietAnh14), I inject JdbcConverter in my custom repository and then I create my own EntityRowMapper :

new EntityRowMapper<>(
    (RelationalPersistentEntity<MyEntity>) this.jdbcConverter.getMappingContext().getRequiredPersistentEntity(MyEntity.class),
    this.jdbcConverter
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

5 participants