openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <>
Subject Re: How to set a default date in JPA when one is not supplied.
Date Thu, 12 Aug 2010 02:36:32 GMT
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
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.


On Wed, Aug 11, 2010 at 2:01 PM, Kelly Kerr <> 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:
> Sent from the OpenJPA Users mailing list archive at

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message