【发布时间】:2019-05-28 01:18:13
【问题描述】:
我是休眠新手,请帮助我。谢谢。
我对@987654322@、java 和oracle 的类型感到困惑。
我在 Oracle 11g 数据库中有 2 种数据类型。 ->
Date,Timestamp(6)我使用 hibernate 映射这个。 ->
date,timestamp它可以映射,比如
Date(DB)到timestamp(hbm)和Date(DB)到Date(hbm)?反之亦然
timestamp(DB)到date(hbm)和timestamp(DB到timestamp(hbm)?那么我应该在 Java 代码中使用什么类型呢?
Oracle DB / Hibernate / Java 代码
日期/日期/日期还是时间戳??
日期/时间戳/日期还是时间戳??
时间戳/日期/日期还是时间戳??
时间戳/时间戳/日期还是时间戳??
四种情况都有可能吗?我很困惑..我在我的 oracle 数据库中进行了测试。
出现一些问题,比如我无法保存小时、分钟、秒......
帮助我了解休眠的基础知识。
hbm.xml 映射文件
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@127.0.0.1:1521:oracle</property>
<property name="hibernate.connection.username">scott</property>
<property name="hibernate.connection.password">scott</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<!-- <property name="hibernate.default_schema">MKYONG</property> -->
<property name="show_sql">true</property>
<mapping resource="com/mkyong/user/DBUser.hbm.xml"></mapping>
</session-factory>
</hibernate-configuration>
用户代码 (java)
public class DBUser implements java.io.Serializable {
private int userId;
private String username;
private String createdBy;
private Date createdDate;
private Date createdTimestamp;
private String createdTest;
//something getter setter ~~
}
【问题讨论】:
-
查看 Oracle 的 documentation,其中显示了 Oracle 到 Java 类型的精确映射表。
标签: java oracle hibernate date timestamp