Default schema mapping of java.util.Date should be "Datetime" in MySQL

1,019 views
Skip to first unread message

takezoux2

unread,
Dec 14, 2011, 9:59:20 PM12/14/11
to Squeryl
When I define java.util.Date field in my table class definition,
squeryl generate schema it as "Date", not "Datetime" in MySQL.
I feel it is not good.There are two reasons.
1. I rarely use "Date" data type in MySQL.
2. java.util.Date contains information not only "Date" but also "Time"

I think java.util.Date should be mapped to "Datetime" type in MySQL.

append.
In MySQL, there are five data type related to time.
Year,Date,Time,Datetime,Timestamp
Year contains only year.
Date contains year , month , date.
Time contains hour, minute seconds.
Datetime and Timestamp contain year,month,date,hour,minute,seconds.
Timestamp is updated automatically when record is updated.

Maxime Lévesque

unread,
Dec 14, 2011, 10:42:55 PM12/14/11
to squ...@googlegroups.com

You can use java.sql.Timestamp, Squeryl will map it to a datetime.
Have you tried this ?

ML

2011/12/14 takezoux2 <take...@gmail.com>

takezoux2

unread,
Dec 19, 2011, 11:06:46 PM12/19/11
to Squeryl
Yes, I tried and it worked.

But I don't think using java.sql.Timestamp is good idea.
java.util.Date is normally used to treat time in Scala or java.
No one expect that hour,minute,second information will be lost after
save when use java.util.Date.
And also when DBObject's datetime fields are defineded as
java.sql.Timestamp, it will be inconvenient to convert java.util.Date
to Timestamp to set field.

There is java.sql.Date class to represent SQL's "Date".
I think java.util.Date should be mapped to "Datetime" or "Timestamp"
and java.sql.Date is mapped to "Date".


thanks


On 12月15日, 午後12:42, Maxime Lévesque <maxime.leves...@gmail.com> wrote:
> You can use java.sql.Timestamp, Squeryl will map it to a datetime.
> Have you tried this ?
>
> ML
>

> 2011/12/14 takezoux2 <takezo...@gmail.com>

David Whittaker

unread,
Dec 20, 2011, 10:42:36 AM12/20/11
to squ...@googlegroups.com
Maybe we can refactor this somewhat in 0.9.6 to have

java.sql.Date -> SQL date
java.sql.Timestamp -> SQL timestamp
java.util.Date -> Configurable precision

The default config could remain "SQL date" for backwards compatibility, but I do think that Yoshi is right about the general expectation and this would give people a way easily override that default behavior. 

BTW, the way that I handle this now is to use Timestamp throughout all of my model classes and I've added a java.util.Date -> java.sql.Timestamp implicit so that I don't have to manually convert when the models are created / updated.

Maxime Lévesque

unread,
Dec 21, 2011, 12:50:34 PM12/21/11
to squ...@googlegroups.com

I see the point, in fact I only use java.sql.Timestamp for the same reason,

it is also true that having it backed by an SQL timestamp column in 0.9.6 is not that big of a
compatibility breakage , since the precision is increased, a decrease of decision would be
more dramatic.

In fact in my 0.9.6 sandbox, I use JodaTime :
  https://github.com/max-l/squeryl-extended-field-types-example/blob/master/src/main/scala/example/MyCustomTypes.scala

So we'll do this in 0.9.6 :

  https://groups.google.com/d/topic/squeryl/LKVUuhTt6ng/discussion

ML

2011/12/20 David Whittaker <da...@iradix.com>

Maxime Lévesque

unread,
Dec 21, 2011, 12:51:10 PM12/21/11
to squ...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages