Hi,

> -----Urspr�ngliche Nachricht-----
> Von: Ralph Tan [mailto:[EMAIL PROTECTED]]
> Gesendet: Donnerstag, 29. August 2002 18:46
> An: 'OJB Users List'
> Betreff: Non-nullable fields with default
> 
> 
> Hello,
> 
>   How do you model a table in repository.xml with a
> non-nullable field that has a dynamic default value
> which will be filled up by the RDBMS. For instance,
> an order table with the following fields
> 
> order_id      int       non-nullable
> customer_id   int       non-nullable
> date_created  datetime  non-nullable  CURRENT_TIMESTAMP
> 
>   Using SQLServer, the date_created has the default
> value of CURRENT_TIMESTAMP which returns the database
> system's current time. The respository looks something
> like this:
> 
>      <field-descriptor id="1"
>          name="orderId"
>          column="order_id"
>          jdbc-type="INTEGER"
>          primarykey="true"
>          autoincrement="true"
>       />
>       <field-descriptor id="2"
>          name="customerId"
>          column="customer_id"
>          jdbc-type="INTEGER"
>       />
>       <field-descriptor id="3"
>          name="dateCreated"
>          column="date_created"
>          jdbc-type="TIMESTAMP"
>       />
> 
>   If I create a new record using ODMG and leaving
> the date_created value as null, an error will occur.
> (The INSERT INTO TABLE command lists all the fields
> and hence an error when a null is assigned to a
> non-nullable field.)
> 
>   A workaround is to leave out the date_created field
> in the respository so that the INSERT INTO TABLE
> command will not have the field. The database server
> will fill that missing field with the default value.
> However, that would also mean that I cannot read back
> the date created since the corresponding BO will not
> be filled with the date created upon reading from the
> table.

You might try to change the class-descriptor dynamically. That is for insert
remove the field-descriptor for dateCreated.
before reading an object you can reinsert this field-descriptor to enable
reading.
Not elegant, but a workaround...

>   Because of requirements, I cannot use the timestamp
> from the Java web server which resides on another
> machine. Or is there a way to get the current timestamp
> from the database server via OJB?

1. you might define the field as locking (locking="true") this will force
automatic assignment of a timestamp at the time of PB.store(). Of course the
timestamp will reflect the time of the java server.

2. To read the time from the database server and to write it into your
instance you can use an instance callback.
you can place the respective lookup code into the beforeStore() method.
please see http://jakarta.apache.org/ojb/tutorial3.html#instance%20callbacks
for an example.

cheers,
Thomas

>   Regards,
> 
> Ralph Tan.
> -- 
> __________________________________________________________
> Sign-up for your own FREE Personalized E-mail at Mail.com
> http://www.mail.com/?sr=signup
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: 
> <mailto:[EMAIL PROTECTED]>
> 

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to