In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what are Hibernate common questions". In daily operation, I believe many people have doubts about Hibernate common questions. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the questions of "what are Hibernate common questions?" Next, please follow the editor to study!
-the concept of hibernate begins-
Hibernate is simply ORM, a technology of object-relational mapping, which directly configures and describes the relationship between POJO objects and DB.
POJO status description:
When using hibernate API to operate a database, there are three states of POJO:
Instantaneous state: the state when POJO.new ()
Persistence state: the state in which the hibernate session object is used for CRUD
Free state: after session is turned off
The [primary key] attribute in POJO should be defined as a wrapper type as much as possible. Although many people think that the basic type data does not need to be sealed and unboxed by objects, in hibernate, primary keys are transformed into objects for operation. Assuming that we set the primary key to the basic data type when designing the POJO, then the hibernate needs to convert after it is accepted, and when the user wants to exchange it, it has to convert the data, which may lead to less efficiency. Therefore, it is recommended that you use packaging data.
It is important to note that unsaved-value is a very important attribute. Hibernate uses this attribute to determine whether an object should be save or update. If the object's id is unsaved-value, it means that the object is not persistence object and will perform save (insert) operations; if id is non-unsaved-value, then the object is persistence object (already exists in the database), as long as update is fine.
-end of hibernate concept-
The following is a summary of common problems with Hibernate:
-
Org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
-
The key to this problem is that the value of unsaved-value does not match the value of id in JOPO.
For example: in POJO.hbm.xml
< id name="id" column="id" type="long" unsaved-value="null">The id attribute type in POJO is the long type (the basic data type, with a value of 0 for myriad data).
Test: now new () a POJO, the default id value must be 0. After finding the POJO node in hibernate-mapping, it is found that the unsaved-value of its id is null, which cannot be matched at this time, and there is no way to start the subsequent judgment, so the above error occurs.
At this point, the study of "what are the common problems of Hibernate" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.