In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to use seqence primary key generation strategy in hibernate, Xiaobian think it is quite practical, so share it for everyone to make a reference, I hope you can gain something after reading this article.
When hibernate uses seqence's primary key generation strategy, it should be written like this (the following writing is for HSQLDB, it is not clear that it is also common in other databases)
Xml Code:
MY_SEQUENCEparam> START WITH 1 INCREMENT BY 1 param> generator> MY_SEQUENCEparam> START WITH 1 INCREMENT BY 1 param> generator>
hibernate actual combat (2nd edition) book is written like this INCREMENT 1 START WITH 1, so write insert call next value for MY_SEQUENCE return is 0, START WITH 1 INCREMENT BY 1 execute call next value for MY_SEQUENCE return is 1, such a strange problem, is hsqldb bug? I didn't do too much research either.
Xml Code:
The dynamic-insert property tells hibernate whether to include null attribute values in the insert statement (set to true, which indicates that null attributes are not included in the insert statement, i.e., attributes included in the insert statement must be non-null fields).
These two attributes can be useful in some ways, such as setting dynamic-update=true in updates. If you update only one attribute, there is no need to put updates to other attributes in sql, and it also improves database execution efficiency. But there is also a side effect, which may be hibernate to compare the values of each attribute to determine whether to include this field in sql statements. Of course, this is useful for classes with more fields. Dynamic-insert is the same when doing insert operations.
Xml Code:
Mark this class as immutable. Hibernate avoids dirty checks. To preserve this immutable property, *** does not write the set method, only the get method. Settings are set by construction. Also explicitly instruct hibernate to access fields of this class via field, rather than via get-set methods, which are set by hibernate-mapping's default-access="field".
Xml Code:
hibernate-mapping>
In general, when you write a class mapping, hibernate is automatically imported into the HQL namespace. You can query HQL only by class name, not package name. Class name to use the specified class. However, there are cases where the same class name in different packages causes ambiguity in HQL, but a good idea is to turn off auto-import properties in hibernate-mapping, take explicit imports, and rename them. This way, you can write directly from Hello in HQL and avoid ambiguity.
Xml Code:
Define the package attribute. You can prefix all class names that do not begin with package names with the defined package in this mapping file.
Xml Code:
The backquotes are there because you think description might be a keyword in a particular database. Hibernate will do specific transformations for you for different databases when you put them in backquotes. For example, sqlserver, hibernate will add [description] to you, mysql will add `description`, and after adding back quotes to description in hsqldb, it will produce "description", which will report errors instead.
Xml Code:
Specifies that the description field is accessed directly through field.
Xml Code:
This formula is evaluated on each query and the attribute is not saved or updated. If you change data in it such as tax_rate, the attribute value is not automatically calculated.
Xml Code:
If update and i nsert are both set to false, this field does not appear in INSERT and UPDATE statements. It is no longer common to add public setting methods to immutable properties in classes.
Xml Code:
The default attribute is useful only when generating table structures. Hibernate does not set default values for null properties in Java classes.
For default to work, dynamic-insert=true must be set in fields with default inserted, which ensures that fields with default properties do not appear in inserts (default field is null), otherwise its value is null (insert NULL instead of default), and after the default value is inserted into the database, because generated=always is set, hibernate will automatically execute a select after insertion to set the properties in the Java class. If the generated property is not set, you need to explicitly call the session.flush() statement.
Xml Code:
class>
If all attributes in component are null, then when querying, the component references are null, that is, hello.getAddress() returns null, as long as at least one is not null, then the reference returned to this component will not be null.
About "how to use seqence primary key generation strategy in hibernate" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.
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.