openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MiƂosz Tylenda <mtyle...@o2.pl>
Subject Re: MappingTool-generated SQL for TIMESTAMP
Date Thu, 23 Dec 2010 16:08:36 GMT
Hi Benjamin,

This is unwanted inconsistency. Would you open a JIRA[1] issue? If not, I will open one.

Maybe a DATETIME would be a better column type for MySQL.

Regards,
Milosz

[1] https://issues.apache.org/jira/browse/OPENJPA


> I think I may have uncovered a bug in the way TIMESTAMP fields are generated
> by the MappingTool.
> 
> I have a field
> 
> @Entity
> public class MyEntity {
> 
>     @Column(name = "due_date")
>     @Temporal(value = TemporalType.TIMESTAMP)
>     private Date dueDate;
> 
> In PostgresSQL, this generates a nullable TIMESTAMP column (with no
> default). No problem.
> 
> In MySQL, it generates
> 
> CREATE TABLE ... ( ..., due_date TIMESTAMP, ...)
> 
> In MySQL 5, this is a field that 1. is not nullable and 2. defaults to
> CURRENT_TIMESTAMP.
> 
> The way to have it behave as a nullable field without a default is to
> specify:
> 
> CREATE TABLE ... ( ..., due_date TIMESTAMP NULL, ...)
> 
> Even if this is not the default behavior (which in my mind it should be, or
> the Postgres one should be changed to behave the same way) the following:
> 
> 
>     @Column(name = "due_date", nullable = true)
>     @Temporal(value = TemporalType.TIMESTAMP)
>     private Date dueDate;
> 
> Should really generate the NULL constraint.
> 
> JPA mavens, what say you?
> 
> Thanks!!
> Benjamin
> 

Mime
View raw message