Hibernate date, timestamp type confusing












0















I'm new to hibernate please help me. thank you.



I am confused of.. types of hibernate, java, and oracle.




  1. I have 2 data types in Oracle 11g Database. -> Date, Timestamp(6)


  2. I mapped this using hibernate. -> date, timestamp


  3. It can be mapped like Date(DB) to timestamp(hbm) and Date(DB) to Date(hbm)?


  4. and vice versa timestamp(DB) to date(hbm) and timestamp(DB to timestamp(hbm)?


  5. then what type should I use in Java Code?



Oracle DB / Hibernate / Java Code




  1. Date / date / Date or timestamp??


  2. Date / timestamp / Date or timestamp??


  3. Timestamp / date / Date or timestamp??


  4. 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 ~~
}









share|improve this question

























  • 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
















0















I'm new to hibernate please help me. thank you.



I am confused of.. types of hibernate, java, and oracle.




  1. I have 2 data types in Oracle 11g Database. -> Date, Timestamp(6)


  2. I mapped this using hibernate. -> date, timestamp


  3. It can be mapped like Date(DB) to timestamp(hbm) and Date(DB) to Date(hbm)?


  4. and vice versa timestamp(DB) to date(hbm) and timestamp(DB to timestamp(hbm)?


  5. then what type should I use in Java Code?



Oracle DB / Hibernate / Java Code




  1. Date / date / Date or timestamp??


  2. Date / timestamp / Date or timestamp??


  3. Timestamp / date / Date or timestamp??


  4. 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 ~~
}









share|improve this question

























  • 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














0












0








0








I'm new to hibernate please help me. thank you.



I am confused of.. types of hibernate, java, and oracle.




  1. I have 2 data types in Oracle 11g Database. -> Date, Timestamp(6)


  2. I mapped this using hibernate. -> date, timestamp


  3. It can be mapped like Date(DB) to timestamp(hbm) and Date(DB) to Date(hbm)?


  4. and vice versa timestamp(DB) to date(hbm) and timestamp(DB to timestamp(hbm)?


  5. then what type should I use in Java Code?



Oracle DB / Hibernate / Java Code




  1. Date / date / Date or timestamp??


  2. Date / timestamp / Date or timestamp??


  3. Timestamp / date / Date or timestamp??


  4. 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 ~~
}









share|improve this question
















I'm new to hibernate please help me. thank you.



I am confused of.. types of hibernate, java, and oracle.




  1. I have 2 data types in Oracle 11g Database. -> Date, Timestamp(6)


  2. I mapped this using hibernate. -> date, timestamp


  3. It can be mapped like Date(DB) to timestamp(hbm) and Date(DB) to Date(hbm)?


  4. and vice versa timestamp(DB) to date(hbm) and timestamp(DB to timestamp(hbm)?


  5. then what type should I use in Java Code?



Oracle DB / Hibernate / Java Code




  1. Date / date / Date or timestamp??


  2. Date / timestamp / Date or timestamp??


  3. Timestamp / date / Date or timestamp??


  4. 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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












1 Answer
1






active

oldest

votes


















0














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





share|improve this answer


























  • 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













  • 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











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
});


}
});














draft saved

draft discarded


















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









0














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





share|improve this answer


























  • 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













  • 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
















0














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





share|improve this answer


























  • 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













  • 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














0












0








0







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





share|improve this answer















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






share|improve this answer














share|improve this answer



share|improve this answer








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 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



















  • 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













  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas