-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Using default server side values for the properties.
PostPosted: Wed May 23, 2007 4:26 am 
Newbie

Joined: Thu Dec 15, 2005 3:03 pm
Posts: 5
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.