简体   繁体   中英

Should spring-data-jdbc EntityRowMapper be allowed to skip properties not in source map?

We are considering introducing Spring Data JDBC into our existing project, to minimize boilerplate code - but we ran into a snag: we have bean-classes that capture all the columns in a table, but we use queries that do not retrieve all the columns since some of the values happen not to be needed in a certain context. Spring Data JDBC's default EntityRowMapper throws an exception when the source map is missing a property that is present in the bean.

Would it be reasonable to expect that this default EntityRowMapper ought to be able to ignore those properties? (indicate it is ok to skip them when creating the result object or have an annotation that allows the programmer to specify a default value to use when it is missing from the source map)

Is it reasonable to expect something like that? Sure, why not.

The reason why it currently isn't this way is two-fold:

  1. If it would be the default behavior it would be easy to select a column with a wrong name and end up with a null value in the entity, without noticing that something went bad.

  2. I consider it bad style. If you just want some of the columns/attributes use a return type that has exactly those columns/attributes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM