Greetings.
Question: How I can use the default values for columns which are set on the server side?
Example: Database table:
Code:
create table (
id int(11) NOT NULL auto_increment,
field1 int(10) NOT NULL default 10,
field2 int(10) NOT NULL default 10
)
Mapping:
Code:
<class
name="package.Table"
table="table"
lazy="false"
>
<id
name="id"
type="java.lang.Integer"
column="ID"
/>
<property
name="field1"
type="int"
column="FIELD1"
not-null="true"
/>
<property
name="field2"
type="int"
column="FIELD2"
not-null="true"
/>
</class>
Using:
Code:
Table table = new Table();
table.setId(1);
table.setField2(20);
session.saveOrUpdate(table);
What should I change in the mapping to do insert for my object with not specified field1 property. I get exception property can't be null in this case. But I want to exclude this field from SQL insert if it is not defined.
Example:
Code:
insert into table (id, field2) values (1,20);
But SQL query should look like the following if field1 is defined 'table.setField1(20)':
Code:
insert into table (id, field1, field2) values (1, 20, 20);
Unfortunately, I did not found answer for my question in the guides. :(
Thanks.