A couple of options come to mind. 1. Let the database assign the default value. You can specify the column definition using the @Column annotation like this : @Column(columnDefinition="TIMESTAMP DEFAULT NOW()") // syntax for MySQL - other databases may require something different private Date created;
2. If you can't alter the table definitions you might be able to use OpenJPA's transaction event listeners<http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_runtime_pm_event>- you'd want to use the beforeCommit() method in this case. The TransactionEvent will contain all entities which participate in the transaction - so you will have to manually select the one(s) you're interested in. hth -mike On Wed, Aug 11, 2010 at 2:01 PM, Kelly Kerr <[email protected]> wrote: > > For an insert/update is there a way to set a default value for a column > using > JPA annotation within the Entity bean? I suppose I could set it in the > EntityManager but would prefer another solution. Thanks.. > -- > View this message in context: > http://openjpa.208410.n2.nabble.com/How-to-set-a-default-date-in-JPA-when-one-is-not-supplied-tp5413502p5413502.html > Sent from the OpenJPA Users mailing list archive at Nabble.com. >
