使用Hibernate将Oracle日期映射到Java对象 [英] Mapping an Oracle Date to a Java object using Hibernate

查看:89
本文介绍了使用Hibernate将Oracle日期映射到Java对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如,下面是Java类中的一些方法:

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

这是来自该类的Hibernate配置文件的映射:

 < property name =dateTimecolumn =date_time> 

以下是该列的DDL:

  CREATE TABLESCHEMA。TABLE_NAME

DATE_TIMEDATE,


我尝试在属性上设置type =date和timestamp(不在同一时间)作为attr在hibernate配置中,然后将Java类型从String更改为Date,但这给了我一个不同的错误。我读了一些关于绑定参数的内容,但无法做出正面或反面的结论。

当我从配置中注释掉其他属性的所有属性时,我肯定这是我的问题。令人讨厌的是,我有另一个表/类映射看似相同的Oracle日期 - > Java字符串映射,不会给我这个问题。

解决方案



 <$ c您最好使用Java.util日期类作为属性来反映oracle日期列。 $ c> Class blah {
private date dateTime;

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

blah(){}

}

当您使用Date作为Java类属性时,错误是什么?


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.

解决方案

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?

这篇关于使用Hibernate将Oracle日期映射到Java对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆