If you don't care about keeping the java object graph and the database
record in sync, then manually create the insert statement using an SQL
Template or with a direct JDBC call.
There's no point using "regular Cayenne objects" in this case.
It's not that I think that using "DB Default value" is bad. I think
default db values are a wonderful idea when used appropriately.
However, the use of a default DB value is incompatible with using an
ORM product like Cayenne since the java object state needs to match
the database record state for ORM to work.
On 3/11/06, WONDER <mmmmmmmmm5..eb.de> wrote:
> Well It looks like the discussion going in the theme using DB default value
> or not.
>
> Your opinion is "using DB default value is bad".
> My opinion is "very good and important".
>
> You dont like it, so its ok for you, but I think its not good idea to
> prevent another developers using DB default value.
>
> btw, indeed solution 1 is not for me, and 2 is not practical.
> I want to use DB default value to do NOT set the value in java :)
>
> Accoring to I insert object in the DB, I know that the object and DB are
> going out of sync. As long as i know that, its ok.
> The problem i see, I know what i want and need "using DB default value", but
> i cant.
>
> Sako.
>
>
> ----- Original Message -----
> From: "Mike Kienenberger" <mkienen..mail.com>
> To: <cayenne-use..bjectstyle.org>
> Sent: Sunday, March 12, 2006 1:12 AM
> Subject: Re: violates not-null constraint question.
>
>
> No, this is how it should work. There's a difference between "allows
> null" and providing a default non-null value.
>
> I think there are two ways you can handle this.
>
> 1) Don't put your is_active column in your model. This is probably
> not realistic in your case.
>
> 2) Have your generated Entity java class set the default rather than
> relying on the database to set the default. When you create the
> object, set a default value for that column.
>
> There are probably a number of reasons why having the database set the
> default is a bad idea, but the primary one is that there's no way for
> your java representation of the object to know what the database is
> doing, and your java object and your database record will be out of
> sync.
>
>
> On 3/11/06, WONDER <mmmmmmmmm5..eb.de> wrote:
> > It does not looks like you expliand. It is exactly as you explaind.
> > No i didnt recreate the table and i wont do that.
> >
> > I want to have it "disallow null" in DB and "allow null" in the model.
> > The default value in the DB should insert the default value.
> >
> > The problem is Cayenne sends "NULL" to DB.
> >
> > I dont think its good style to use NULL at all in Cayenne. According to
> > sending NULL to db mean
> > I have no way to use the defaul value feature of the DB. This is nonsence,
> > isnt it?
> >
> > Sako.
> >
> > ----- Original Message -----
> > From: "Mike Kienenberger" <mkienen..mail.com>
> > To: <cayenne-use..bjectstyle.org>
> > Sent: Saturday, March 11, 2006 10:33 PM
> > Subject: Re: violates not-null constraint question.
> >
> >
> > It looks like you have set the is_active field as "allows null" in the
> > modeler, but you have set the database constraints to be "disallows
> > null".
> >
> > Have you tried recreating the table after making the mandatory change?
> > Or altering the table column to be nullable?
> >
> > -Mike
> >
> >
> > On 3/11/06, WONDER <mmmmmmmmm5..eb.de> wrote:
> > > Hello,
> > >
> > > CREATE TABLE account
> > > (
> > > id int4 NOT NULL,
> > > username varchar(50) NOT NULL,
> > > "password" varchar(100) NOT NULL,
> > > is_checked bool DEFAULT false,
> > >
> > > ...
> > >
> > > In the Model i have unchecked DbEntity.Mandatory for "is_active" to
> > false.
> > >
> > > I get this error
> > >
> > > ERROR: null value in column "is_active" violates not-null constraint
> > >
> > > Is there any way to get arround this?
> > >
> > > I really dont know what sence does it make to send a NULL value to the
> DB
> > as
> > >
> > > ----------------------------------------------------------------
> > >
> > > INSERT INTO public.account (id, inactive_username, is_active,
> is_checked,
> > > password, username) VALUES (?, ?, ?, ?, ?, ?)
> > >
> > > [batch bind: 47, NULL, NULL, 'false', '*****', 'XXXXX']
> > >
> > > ----------------------------------------------------------------
> > >
> > > It makes the default value technique useless, i hope there is way to
> > disable
> > > this.
> > >
> > >
> > >
> > > Sako.
> > >
> > >
> > >
> > >
> >
> >
>
>
This archive was generated by hypermail 2.0.0 : Sat Mar 11 2006 - 22:18:38 EST