Application of Date and sequence in Oracle Hibernate

Source: Internet
Author: User

This article mainly introduces the actual application of Date and sequence in Oracle Hibernate in the form of code. If you are puzzled by the actual application and operation of Date and sequence in Oracle Hibernate, you can read the following articles to learn about it.

Date and sequence in Oracle Hibernate

 
 
  1. Ocreate table tb_bill (   
  2. bill_id INTEGER not null,   
  3. shop_id INTEGER,   
  4. bill_content VARCHAR2(200),   
  5. bill_handler VARCHAR2(20),   
  6. billdate DATE,   
  7. constraint PK_TB_PRICEBILL primary key (bill_id)   
  8. );  

Sequence:

 
 
  1. create sequence SEQ_TB_BILL  

Configuration file:

 
 
  1. <id name="id" unsaved-value="0">   
  2. <column name="bill_id"/>   
  3. <generator class="sequence">   
  4. <param name="sequence">SEQ_TB_BILL </param>   
  5. </generator>   
  6. </id>   
  7. <property name="shopId" column="shop_id"/>   
  8. <property name="billcontent" column="bill_content"/>   
  9. <property name="billHandler" column="bill_handler"/>   
  10. <property name="billDate" column="billdate" type=
    "" type="timestamp"/>   
  11. bean:   
  12. private int shopId;   
  13. private String billcontent;   
  14. private String billHandler;   
  15. private Date billDate;   

Date and sequence methods in Oracle Hibernate are automatically generated without writing them! Follow the steps below to save the bean:

 
 
  1. Bill model = new Bill();   
  2. model.setBillcontent("neirong");   
  3. model.setBillHandler("handler");   
  4. model.setBillPrice(123.02);   
  5. model.setShopId(2);   
  6. BillDAO.save(model);   
  7. System.out.println(model.getId());  

If the problem occurs, then the Date database, when a new java. util. it is normal that the Date () is retained, but the bill_id of the sequence has a problem. The number is too large, leading to exceeding the int range, if the billDate field in the database is removed, everything is normal and bill_id is saved as normal. The method is normal in other classes.

This is abnormal. Other classes also have time for Date, which is extremely depressing for two days. Later, the time will be automatically saved from the database! The above is an introduction to Date and sequence related content in Oracle Hibernate. I hope you will gain some benefits.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.