Spring - How to use BeanPropertyRowMapper without column name processing

I am working on an application that has been converted from pure JDBC to a Spring template using mapper. The problem that I have is that the column in the database does not match the property names, which do not allow me to use BeanPropertyRowMapper easily.

I saw several posts about using aliases in queries. This will work, but it makes it impossible to execute SELECT *

Is there any annotation that can be used with BeanPropertyRowMapper like @Column from JPA?

+4
source share
1 answer

I saw several posts about using aliases in queries

This is actually the approach suggested in JavaDocs:

To facilitate matching columns and fields that do not have matching names, try using column aliases in the SQL expression, for example, "select fname as first_name from client".

From: BeanPropertyRowMapper .

unable to execute SELECT *

Please do not use SELECT * . This makes you vulnerable to any changes to the database schema, including those fully compatible with feedback, such as adding or reordering columns.

Is there any annotation that can be used with BeanPropertyRowMapper like @Column from JPA?

Yes, it is called , and possibly . Seriously, either using aliases or using your own RowMapper , Spring is not a fully functional orm .

+5
source

Source: https://habr.com/ru/post/1398656/


All Articles