hibernate mysql date ClassCastException September 27, 2006
Posted by javafoo in hibernate, javanotes, mysql.1 comment so far
java.lang.ClassCastException
[java] at org.hibernate.type.DateType.deepCopyNotNull(DateType.java)
[java] at org.hibernate.type.NullableType.deepCopy(NullableType.java)
Does this look familiar. This happens when you define a java.util.Date field in the POJO and try to map it to a mysql ‘date’ datatype. This happens because a ‘date’ datatype represents only the date part and does not include the time part in mysql world, whereas java.util.Date is date+time. Although in Oracle and DB2 and probably other databases a date datatype is actually date+time. If the corresponding field is defined as a ‘datetime’ type in mysql then you should be fine. Also when using hibernate cfg doclet to create the database schemas do not explicitly say type=”date”, let reflection take care of it. Otherwise doclet will map it to date datatype for mysql, which will cause you this grief, leave it to doclet and it will correctly map it to datetime.
MySQL: access denied for user: (Using password: YES) June 30, 2005
Posted by javafoo in javanotes, jdbc, mysql.13 comments
More experimenting with struts. So I got ambitious, downloaded MySQL and tried to wire a database into my simple struts app. Setting up MySQL was a breeze, although it was my first time, except that some time was wasted googling for user account creation etc.
So, I set up a datasource in Tomcat, which could be looked up by JNDI. I added this in server.xml.
But was getting errors with Context.lookup, indicating there was no “java:comp/env/jdbc” in the Context. Realized I forgot to add the resource-ref in my web descriptor.
This done, I was getting a different error.
Access denied for user ‘blah’: (Using password: YES).
What the …, I didn’t set the password as YES, what the heck was going on?
So googled again (one of these days, when someone asks me what tools, IDE I use for development, I will be sure to add ‘Google’ in there, in fact this should come integrated with the IDE, any Exception or Error message should be linked to Google search), anyway I digress.
So this seems to be a common problem. I tweak the user account a bit in MySQL, apparently the host shouldn’t be set as ‘%’, you are better off setting it to ‘localhost’. I also deleted the default user account ”, which is an empty string. So either of these fixed it for me and I am on my way.
Since I am seeing a lot of searches to this post and one of the commentors (Tyler) rightfully indicates that: The “YES” doesn’t mean that you are using the password “Yes” it simply means “Yes” you are using a password. If the password was blank it would have said “No”
That’s what I thought the issue was to start with (that somehow the password was set to ‘Yes’) or atleast that’s what the MySQL message led me to believe, but later when I tweaked the User Account to set the host, I realized what it was trying to tell me.