In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use Hibernate Sequence". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use Hibernate Sequence.
First, there are two ways to create self-growing segments for tables.
One is that different tables use their own Hibernate Sequence, as follows:
1. Create sequence create sequence seq_idminvalue 1start with 1increment by 1cache 20 first in Oracle sequence
two。 Configure seq_id in your hbm.xml
When you insert the data again, Hibernate automatically generates the following statement:
Hibernate: select seq_id.nextval from dual hibernate: insert into YXJK.T_YXJK_WHRYTXL (XM0000, ZW0000, LXDH00, SJHM00, DZYJ00,IP0000, ID0000) values (? ,? ,? ,? ,? ,? ,? )
Automatically generates the next sequence value, and then inserts the object into the table. When using it, it should be noted that the primary key of Hibernate for sequence must be shor,long, or integer.
Second, another way is to use the public sequence
At this time, the sequence used by the table can not be specified, then the corresponding hbm.xml is:
Then create a common Hibernate sequence object named hibernate_sequence
◆ create sequence hibernate_sequence
◆ minvalue 0
◆ maxvalue 99999999
◆ start with 10000
◆ increment by 1
Three points for attention
If the database is migrated from other databases such as sqlserver, the starting value of creating sequence should be larger than the ID value of * * in the current table, otherwise an error will occur because sequence will not maintain whether it duplicates with the existing value before the library is imported.
1. Sequence: for Oracle database
2. Native: used across databases and generated by underlying dialects.
Default.sequence is hibernate_sequence
Note: when using native, Hibernate will find the hibernate_sequence sequence in Oracle by default. If the sequence is not in Oracle, an error will be reported when connecting to the Oracle database.
Thank you for your reading, the above is the content of "how to use Hibernate Sequence", after the study of this article, I believe you have a deeper understanding of how to use Hibernate Sequence, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.