简体   繁体   中英

Read-only column mapped using MyBatis Generator

Firebird database supports read-only columns. Columns that have their values computed, not updated. If I map some table with read-only columns using MyBatis Generator I receive the following error while inserting into or updating the table:

org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544359. attempted update of read-only column org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544359. attempted update of read-only column .

How to treat this kind of column using MyBatis Generator? Is it possible to have insert and update statements ignoring this kind of column?

Note : Using insertSelective and updateSelective passing the read-only columns values as null , instead of using insert and update , will solve only the cases where I don't want to update other fields to null . So, I need another solution.

MyBatis does not offer additional support to read-only columns. So, the turnaround solution is to set the read only columns with the ignoreColumn tag and to write the queries that need that column value manually, using @Select annotations in mappers.

<table tableName="...">
    ...
    <ignoreColumn column="<read only column>" /> 
    ...
</table>

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