Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping an Oracle Date to a Java object using Hibernate

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.

like image 470
Nathan Spears Avatar asked Jun 07 '09 00:06

Nathan Spears


People also ask

What is temporal annotation in Hibernate?

The @Temporal annotation has the single parameter value of type TemporalType. It can be either DATE, TIME or TIMESTAMP, depending on the underlying SQL type that we want to use for the mapping.

How mapping is implemented in hibernate?

Define Hibernate Mapping FileThe <class> elements are used to define specific mappings from a Java classes to the database tables. The Java class name is specified using the name attribute of the class element and the database table name is specified using the table attribute.

What is Hibernate mapping in Java?

hibernate mappings are one of the key features of hibernate . they establish the relationship between two database tables as attributes in your model. that allows you to easily navigate the associations in your model and criteria queries.


1 Answers

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?

like image 124
Martlark Avatar answered Sep 19 '22 14:09

Martlark