Hibernate date, timestamp type confusing
I'm new to hibernate please help me. thank you.
I am confused of.. types of hibernate
, java
, and oracle
.
I have 2 data types in Oracle 11g Database. ->
Date
,Timestamp(6)
I mapped this using hibernate. ->
date
,timestamp
It can be mapped like
Date(DB)
totimestamp(hbm)
andDate(DB)
toDate(hbm)
?and vice versa
timestamp(DB)
todate(hbm)
andtimestamp(DB
totimestamp(hbm)
?then what type should I use in Java Code?
Oracle DB / Hibernate / Java Code
Date / date / Date or timestamp??
Date / timestamp / Date or timestamp??
Timestamp / date / Date or timestamp??
Timestamp / timestamp / Date or timestamp??
four cases are all possible? I am so confused.. I tested in my oracle db.
some problems occur like I can not save hours, minutes, seconds..
Help me learn the basics of hibernate.
hbm.xml mapping file
<?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>
User Code (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 ~~
}
java oracle hibernate date timestamp
add a comment |
I'm new to hibernate please help me. thank you.
I am confused of.. types of hibernate
, java
, and oracle
.
I have 2 data types in Oracle 11g Database. ->
Date
,Timestamp(6)
I mapped this using hibernate. ->
date
,timestamp
It can be mapped like
Date(DB)
totimestamp(hbm)
andDate(DB)
toDate(hbm)
?and vice versa
timestamp(DB)
todate(hbm)
andtimestamp(DB
totimestamp(hbm)
?then what type should I use in Java Code?
Oracle DB / Hibernate / Java Code
Date / date / Date or timestamp??
Date / timestamp / Date or timestamp??
Timestamp / date / Date or timestamp??
Timestamp / timestamp / Date or timestamp??
four cases are all possible? I am so confused.. I tested in my oracle db.
some problems occur like I can not save hours, minutes, seconds..
Help me learn the basics of hibernate.
hbm.xml mapping file
<?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>
User Code (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 ~~
}
java oracle hibernate date timestamp
Have a look at Oracle's documentation which shows a table of exact mappings of Oracle to Java types.
– Tim Biegeleisen
Dec 31 '18 at 14:41
add a comment |
I'm new to hibernate please help me. thank you.
I am confused of.. types of hibernate
, java
, and oracle
.
I have 2 data types in Oracle 11g Database. ->
Date
,Timestamp(6)
I mapped this using hibernate. ->
date
,timestamp
It can be mapped like
Date(DB)
totimestamp(hbm)
andDate(DB)
toDate(hbm)
?and vice versa
timestamp(DB)
todate(hbm)
andtimestamp(DB
totimestamp(hbm)
?then what type should I use in Java Code?
Oracle DB / Hibernate / Java Code
Date / date / Date or timestamp??
Date / timestamp / Date or timestamp??
Timestamp / date / Date or timestamp??
Timestamp / timestamp / Date or timestamp??
four cases are all possible? I am so confused.. I tested in my oracle db.
some problems occur like I can not save hours, minutes, seconds..
Help me learn the basics of hibernate.
hbm.xml mapping file
<?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>
User Code (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 ~~
}
java oracle hibernate date timestamp
I'm new to hibernate please help me. thank you.
I am confused of.. types of hibernate
, java
, and oracle
.
I have 2 data types in Oracle 11g Database. ->
Date
,Timestamp(6)
I mapped this using hibernate. ->
date
,timestamp
It can be mapped like
Date(DB)
totimestamp(hbm)
andDate(DB)
toDate(hbm)
?and vice versa
timestamp(DB)
todate(hbm)
andtimestamp(DB
totimestamp(hbm)
?then what type should I use in Java Code?
Oracle DB / Hibernate / Java Code
Date / date / Date or timestamp??
Date / timestamp / Date or timestamp??
Timestamp / date / Date or timestamp??
Timestamp / timestamp / Date or timestamp??
four cases are all possible? I am so confused.. I tested in my oracle db.
some problems occur like I can not save hours, minutes, seconds..
Help me learn the basics of hibernate.
hbm.xml mapping file
<?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>
User Code (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 ~~
}
java oracle hibernate date timestamp
java oracle hibernate date timestamp
edited Dec 31 '18 at 18:25
Thelouras
5111719
5111719
asked Dec 31 '18 at 14:35
yhleeyhlee
32
32
Have a look at Oracle's documentation which shows a table of exact mappings of Oracle to Java types.
– Tim Biegeleisen
Dec 31 '18 at 14:41
add a comment |
Have a look at Oracle's documentation which shows a table of exact mappings of Oracle to Java types.
– Tim Biegeleisen
Dec 31 '18 at 14:41
Have a look at Oracle's documentation which shows a table of exact mappings of Oracle to Java types.
– Tim Biegeleisen
Dec 31 '18 at 14:41
Have a look at Oracle's documentation which shows a table of exact mappings of Oracle to Java types.
– Tim Biegeleisen
Dec 31 '18 at 14:41
add a comment |
1 Answer
1
active
oldest
votes
You can use for both HBM and JAVA.
java.sql.Timestamp for Timestamp. TIMESTAMP in Oracle
java.sql.Date for Date. DATE in Oracle
Both the above classes extends from java.util.Date. You can use java.sql.Timestamp for both but the time component will be discarded by Oracle for DATE during INSERT/UPDATE. Using java.sql.Date for DATE will give you clarity.
From Java 8 onwards,you can use below.
org.hibernate.type.LocalDateType - Maps a java.time.LocalDate to a Oracle DATE
org.hibernate.type.LocalDateTimeType - Maps a java.time.LocalDateTime to a Oracle TIMESTAMP
very thank you!! thank you for solving my problem
– yhlee
Dec 31 '18 at 16:41
Actually, all of those terrible date-time classes were supplanted years ago by the modern java.time classes. JDBC 4.2 and later provides for direct exchange of java.time objects. Hibernate has been updated as well: hibernate.atlassian.net/plugins/servlet/mobile#issue/HHH-8844. No need to ever touch thejava.sql.Timestamp
,Java.sql.Date
, orjava.util.Date
classes again.
– Basil Bourque
Jan 1 at 7:42
Thanks @BasilBourque I kept the answer close to the question. Now I have update it for Java 8.
– Ashraff Ali Wahab
Jan 2 at 19:09
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53988605%2fhibernate-date-timestamp-type-confusing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use for both HBM and JAVA.
java.sql.Timestamp for Timestamp. TIMESTAMP in Oracle
java.sql.Date for Date. DATE in Oracle
Both the above classes extends from java.util.Date. You can use java.sql.Timestamp for both but the time component will be discarded by Oracle for DATE during INSERT/UPDATE. Using java.sql.Date for DATE will give you clarity.
From Java 8 onwards,you can use below.
org.hibernate.type.LocalDateType - Maps a java.time.LocalDate to a Oracle DATE
org.hibernate.type.LocalDateTimeType - Maps a java.time.LocalDateTime to a Oracle TIMESTAMP
very thank you!! thank you for solving my problem
– yhlee
Dec 31 '18 at 16:41
Actually, all of those terrible date-time classes were supplanted years ago by the modern java.time classes. JDBC 4.2 and later provides for direct exchange of java.time objects. Hibernate has been updated as well: hibernate.atlassian.net/plugins/servlet/mobile#issue/HHH-8844. No need to ever touch thejava.sql.Timestamp
,Java.sql.Date
, orjava.util.Date
classes again.
– Basil Bourque
Jan 1 at 7:42
Thanks @BasilBourque I kept the answer close to the question. Now I have update it for Java 8.
– Ashraff Ali Wahab
Jan 2 at 19:09
add a comment |
You can use for both HBM and JAVA.
java.sql.Timestamp for Timestamp. TIMESTAMP in Oracle
java.sql.Date for Date. DATE in Oracle
Both the above classes extends from java.util.Date. You can use java.sql.Timestamp for both but the time component will be discarded by Oracle for DATE during INSERT/UPDATE. Using java.sql.Date for DATE will give you clarity.
From Java 8 onwards,you can use below.
org.hibernate.type.LocalDateType - Maps a java.time.LocalDate to a Oracle DATE
org.hibernate.type.LocalDateTimeType - Maps a java.time.LocalDateTime to a Oracle TIMESTAMP
very thank you!! thank you for solving my problem
– yhlee
Dec 31 '18 at 16:41
Actually, all of those terrible date-time classes were supplanted years ago by the modern java.time classes. JDBC 4.2 and later provides for direct exchange of java.time objects. Hibernate has been updated as well: hibernate.atlassian.net/plugins/servlet/mobile#issue/HHH-8844. No need to ever touch thejava.sql.Timestamp
,Java.sql.Date
, orjava.util.Date
classes again.
– Basil Bourque
Jan 1 at 7:42
Thanks @BasilBourque I kept the answer close to the question. Now I have update it for Java 8.
– Ashraff Ali Wahab
Jan 2 at 19:09
add a comment |
You can use for both HBM and JAVA.
java.sql.Timestamp for Timestamp. TIMESTAMP in Oracle
java.sql.Date for Date. DATE in Oracle
Both the above classes extends from java.util.Date. You can use java.sql.Timestamp for both but the time component will be discarded by Oracle for DATE during INSERT/UPDATE. Using java.sql.Date for DATE will give you clarity.
From Java 8 onwards,you can use below.
org.hibernate.type.LocalDateType - Maps a java.time.LocalDate to a Oracle DATE
org.hibernate.type.LocalDateTimeType - Maps a java.time.LocalDateTime to a Oracle TIMESTAMP
You can use for both HBM and JAVA.
java.sql.Timestamp for Timestamp. TIMESTAMP in Oracle
java.sql.Date for Date. DATE in Oracle
Both the above classes extends from java.util.Date. You can use java.sql.Timestamp for both but the time component will be discarded by Oracle for DATE during INSERT/UPDATE. Using java.sql.Date for DATE will give you clarity.
From Java 8 onwards,you can use below.
org.hibernate.type.LocalDateType - Maps a java.time.LocalDate to a Oracle DATE
org.hibernate.type.LocalDateTimeType - Maps a java.time.LocalDateTime to a Oracle TIMESTAMP
edited Jan 2 at 19:07
answered Dec 31 '18 at 15:48
Ashraff Ali WahabAshraff Ali Wahab
803513
803513
very thank you!! thank you for solving my problem
– yhlee
Dec 31 '18 at 16:41
Actually, all of those terrible date-time classes were supplanted years ago by the modern java.time classes. JDBC 4.2 and later provides for direct exchange of java.time objects. Hibernate has been updated as well: hibernate.atlassian.net/plugins/servlet/mobile#issue/HHH-8844. No need to ever touch thejava.sql.Timestamp
,Java.sql.Date
, orjava.util.Date
classes again.
– Basil Bourque
Jan 1 at 7:42
Thanks @BasilBourque I kept the answer close to the question. Now I have update it for Java 8.
– Ashraff Ali Wahab
Jan 2 at 19:09
add a comment |
very thank you!! thank you for solving my problem
– yhlee
Dec 31 '18 at 16:41
Actually, all of those terrible date-time classes were supplanted years ago by the modern java.time classes. JDBC 4.2 and later provides for direct exchange of java.time objects. Hibernate has been updated as well: hibernate.atlassian.net/plugins/servlet/mobile#issue/HHH-8844. No need to ever touch thejava.sql.Timestamp
,Java.sql.Date
, orjava.util.Date
classes again.
– Basil Bourque
Jan 1 at 7:42
Thanks @BasilBourque I kept the answer close to the question. Now I have update it for Java 8.
– Ashraff Ali Wahab
Jan 2 at 19:09
very thank you!! thank you for solving my problem
– yhlee
Dec 31 '18 at 16:41
very thank you!! thank you for solving my problem
– yhlee
Dec 31 '18 at 16:41
Actually, all of those terrible date-time classes were supplanted years ago by the modern java.time classes. JDBC 4.2 and later provides for direct exchange of java.time objects. Hibernate has been updated as well: hibernate.atlassian.net/plugins/servlet/mobile#issue/HHH-8844. No need to ever touch the
java.sql.Timestamp
, Java.sql.Date
, or java.util.Date
classes again.– Basil Bourque
Jan 1 at 7:42
Actually, all of those terrible date-time classes were supplanted years ago by the modern java.time classes. JDBC 4.2 and later provides for direct exchange of java.time objects. Hibernate has been updated as well: hibernate.atlassian.net/plugins/servlet/mobile#issue/HHH-8844. No need to ever touch the
java.sql.Timestamp
, Java.sql.Date
, or java.util.Date
classes again.– Basil Bourque
Jan 1 at 7:42
Thanks @BasilBourque I kept the answer close to the question. Now I have update it for Java 8.
– Ashraff Ali Wahab
Jan 2 at 19:09
Thanks @BasilBourque I kept the answer close to the question. Now I have update it for Java 8.
– Ashraff Ali Wahab
Jan 2 at 19:09
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53988605%2fhibernate-date-timestamp-type-confusing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have a look at Oracle's documentation which shows a table of exact mappings of Oracle to Java types.
– Tim Biegeleisen
Dec 31 '18 at 14:41