java - How Can I Use Hibernate JPA @SQLInsert With a Database Column Having a Default Value -
i have table "groups" 4 columns. database postgres , group_id column serial. in reality integer default next value.
i have use case need use @sqlinsert (using normal persist method not option), can't work default. here have:
@sqlinsert(sql="insert groups (group_id, parent_id, group_name, version) values (default,?,?,?)") i set entity attributes values group_id , version null, , other 2 correctly populated. group_id not nullable in db, version can null.
i exception:
warning: sql error: 0, sqlstate: 22023 severe: column index out of range: 4, number of columns: 3. severe: not synchronize database state session if enter following dml directly on database, works:
insert groups (group_id, parent_id, group_name, version) values (default, 3, 'abcd', null); is there way make same thing happen using @sqlinsert.
if class members want save not reference types can not hold null value. may cause of failure in synchronization database records. try use reference types integer , double, etc. , sure default values assumed direct insert query.
another thing in error messages. may default value out of boundary of type using in java column. check default value in range. if value out of range set class member, can't synced.
edit: sorry, second part not true in case.
Comments
Post a Comment