This is strange. Do you definitely see NULL printed in INSERT when
commit is executed? Everything is rather straightforward in your code,
and shouldn't cause any trouble.
> java.util.Date aDate = new java.util.Date();
> long dateLong = aDate.getTime();
> java.sql.Date sqlDate = new java.sql.Date(dateLong);
> uniquePlace.setDatecreated(sqlDate);
How is the "datecreated" mapped in the ObjEntity? As "java.sql.Date"?
I am using "java.util.Date" mapping almost exclusively, so I may have
overlooked some issues using SQL date types. Not that it should make
much difference, but you can try mapping Java attribute as
"java.util.Date" and replace the code above with
"uniquePlace.setDatecreated(new java.util.Date())". Cayenne will take
care of proper conversions.
If the date trick above doesn't make a difference we should look
elsewhere. Setting an attribute is a very basic thing and it should
just work.
> I'm using Cayenne 1.1.0rc1
I guess you mean 1.0rc1, since 1.1 still has no official releases? I
would recommend an upgrade to 1.0.5 regardless of the current problem.
Andrus
On Jan 12, 2004, at 1:50 PM, Gottlieb, Robert SPAWAR wrote:
> I have an CayenneDataObject UniquePlace that has an attribute:
> java.sql.Date datecreated
> In the MySQL 4.0 database, the corresponding column is: DATECREATED of
> type date
>
> I'm using Cayenne 1.1.0rc1 and I tried Cayenne 1.0.5 and got the same
> results, which is that the datecreated
> attribute is NULL before it gets committed to the database. The
> problem is that the field is not allowed to be NULL
> in the database.
>
> The code I'm using to set this up is as follows:
>
> UniquePlace uniquePlace = new UniquePlace();
>
> ctxt.registerNewObject(uniquePlace);
> ..
> ..
> java.util.Date aDate = new java.util.Date();
> long dateLong = aDate.getTime();
> java.sql.Date sqlDate = new java.sql.Date(dateLong);
> uniquePlace.setDatecreated(sqlDate);
> ctxt.setTransactionEventsEnabled(true);
> ctxt.commitChanges(Level.WARN);
This archive was generated by hypermail 2.0.0 : Mon Jan 12 2004 - 14:21:09 EST