hibernate @formula select only field -
i following tutorial on hibernate , have field on entity should select only. however, upon save of entity filed in insert query , ending on error. please assist.
@entity @table(name="finances_user") @access(value=accesstype.property) public class user { ... private date birthdate; @formula("lower(datediff(curdate(), birth_date)/365)") private int age; @column("birth_date") public int getage() { return age; } public void setage(int age) { this.age = age; } ... }
i have tried below well,
@formula(value = "select lower(datediff(curdate(), birth_date)/365) finances_user l l.user_id = userid")
below error stack, field 'age' used in insert query. should select field.
debug - insert finances_user (age, birth_date, created_by, created_date, email_address, first_name, last_name, last_updated_by, last_updated_date, user_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) debug - not execute statement [n/a] com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: unknown column 'age' in 'field list'
you have annotated entity @access(value=accesstype.property)
means hibernate uses getters determine property names mapped columns in db. , have getage()
. remove annotation in order relate fields annotated @column
appropriate columns in db.
Comments
Post a Comment