5

I get the message "literal does not match format string".

For instance, here are some methods from a Java class:

public String getDateTime();
public void setDateTime(String date_time);

Here is the mapping from the Hibernate config file for that class:

<property name="dateTime" column="date_time">

and here is the DDL for that column:

 CREATE TABLE "SCHEMA"."TABLE_NAME" 
   (    
    "DATE_TIME" DATE, 
    etc.
   )

I tried setting type="date" and "timestamp" (not at the same time) as an attr on the property in the hibernate config, and then changing the Java type from String to Date, but that gave me a different error. I read something about binding the parameter but couldn't make heads or tails of that.

When I comment out that property from the config everything else is working, so I'm sure that's my issue. The annoying thing is that I have another table/class mapping with seemingly the same Oracle Date->Java String mapping that doesn't give me this problem.

2 Answers 2

8

You would be better off using a Java.util date class as the property to reflect the oracle date column.

Class blah{
private Date dateTime;

public Date getDateTime();
public void setDateTime(Date dateTime);

blah(){}

}

What was the error when you used Date as the Java class property?

Sign up to request clarification or add additional context in comments.

2 Comments

Guh. I don't think I changed the setter method parameter's type from String to Date the first time. Feeling dumb, because it worked like clockwork this time.
This only works if you DO NOT include the "type" attribute in the mapping property: <property name="dateTime" column="date_time"> If you include the type with a value of either "date" or "timestamp" it will not accurately convert the values. So the following is BAD: <property name="dateTime" column="date_time" type="date"> Here is a link explaining why this is true: fishbowl.pastiche.org/2005/07/13/… and here is a link explaining the solution: enavigo.com/2007/10/20/mapping-hibernate-to-oracle-date-fields
2

The type of your dateTime attribute should be Timestamp or Date, that should automatically convert Oracle date/time to it. I don't see the point of keeping date as a String since you have to involve the formatting.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.