1. What is ORM referring to? Please tell me what you think of it. ObjectRelational mapping, like a mirror, implements automated mapping of programs to databases. The object-oriented approach to development has become a mainstream development approach in today's enterprise application development environment. A relational database is a mainstream data storage system that permanently stores databases in an enterprise-level application environment. So Object-The relational mapping system usually exists in the form of middleware, which mainly realizes the mapping of program object to relational database data. 2. What are the common objects when using hibernate? (1), we found hibernate printing too much information while performing the operation. To solve this problem, we will configure the log4j in the project and then adjust the print level. Step: 1, add Log4j.jar to the Project class library 2, copy the log4j.properties to the SRC directory and adjust the print level (Debug,info,warn,error) (2), Hibernate performs the operation on the data, compared to JDBC: JDBC is autocommit autocommit. Hibernate defaultFalse. Therefore, we must start the transaction very clearly. (3), Hibernate core Api:configuration, Sessionfactory, Session, Transaction 3. What are the three states of the objects in the session, and how they are converted, and the difference between the three states. Three states of the object: (1) instantaneous/Temporary state (no relationship with session) (2) Persistence (related to Session object, stored in the session as map) (3) managed/Free State (unrelated to the session object, which is to close the Session object) to complement the focus--1--:1, ensure that all persistent state objects and database records are consistent at commit. 2, the persisted object is saved in the session cache. Multiple queries are read directly from the cache, improving the efficiency of the query. Supplementary Focus--2--: Persist the object, testing the get and load methods. Get method: First in the session cache (cache), if none, and then in the Sessionfacotory (level two cache) to find, if no further to the database lookup, not yet, return null Load method: Generally we can guarantee that this record must exist, This method has lazy loading. 4. How are the primary keys generated in several ways, and what are their respective uses? *Native(very common): for Oracle with sequence mode, for MySQL and SQL Server identity (self-increment primary key generation mode), native is the primary key generation work to the database to complete, according to the ability of the underlying database, Choose a high flexibility from the identity sequence Hilozhong. *Assigned (very common): when inserting data, the primary key is added by the user, hibernate no matter *Sequence:oracle very Popular *Identity: Using MySQL and SQL Server are common. cannot be used in Oracle *Hilo *uuid: Using a 128-The bit's UUID algorithm generates identifiers for string types. The UUID is encoded as a 32-bit, 16-digit string. UUID is often used to generate a fully unique case of a primary key value, a globally unique identity. 5. Let's talk about lazy loading when the program calls to reload, when we need to access the volume of data is too large, memory capacity is limited. We let the data load when we need it, reducing the resource memory consumption. 6. The Get and load method differences of the session, the difference between list and iterate get and load common: first cache (session), level two cache (sessionfactory), if not taken in the database to find Get and load differences: The Get method does not have lazy loading problem, if the ID corresponding to the record does not exist, then the null load method has lazy loading problem, if the ID corresponding record does not exist, then throws an exception *Iterate can use a level two cache (sessionfactory). First go to the database to query the required ID, and then in the two-level cache to check whether the ID corresponding to the object. If there is, take it out directly if not, then go to the database to find it. The use of iterate, if the result is not in the level two cache, instead of a more SQL statement, reducing performance *The list defaults to the level two cache where the results are placed in a level two cache, but the list itself does not use a level two cache when queried. 7. Talk about your understanding of annotation. Annotation is a configuration file, which embodies the contents of the XML configuration file in the code, avoiding the development process of multiple files/Change the environment. Jdk5 annotation method annotations are more abstract compared to the environment configuration. *Annotations are not code that will not be executed on the code description ability, combined with the reflection mechanism will do a lot of things for us *The use of annotations allows us to no longer write XML configuration (mapping) files as frequently as before, to some extent improving the efficiency of development steps: 1, introducing hibernate-related jar packages into 2, introducing 3 jar packages for annotations: Hibernate-annotations.jar Ejb3-persistence.jar hibernate-commons-Annotations.jar 9. Hibernate how to pagination, please write on paper example: String hql = "from Emp"; Query query =Session.createquery (HQL); Query.setfirstresult (0);//Starting from the first few data Query.setmaxresult (10);//Set the maximum number of records to display per page 10. Hibernate condition query, criteria, have you ever used it? How do you usually use those methods? The Criteria API is an interface within the Java language, directly manipulating the underlying object, and writing out the query code is not universal. Performance is optimized for maximum use. Conditional filtering queries are not commonly used, for example: Criteria c = Session.createcriteria (Emp.Class);//Combined with reflective C.add (RESTRICTIONS.IDEQ (1)); List List =C.list (); 11. What is a first-level cache and what do you know about it? The first-level cache is: Session cache. We know that the session acts as a scope for a conversation. Understanding: The session has a short life cycle, the first level of the fastest cache life in the session is of course also very short, so the first level cache hit rate (utilization) is also very low the performance of the system to improve (---low repetition rate)is also very limited, the main function of the session internal cache is to keep the session internal data state synchronization management: Application call session () of Save (), update (), Saveorupdate (), get (), load () and a list () that invokes the query interface, iterator () will add the object to the first level of cache if the corresponding object is not already present in the session cache. , can be through close/clear/Evict empty the cache. Evict: Clears an object clear: Clears all objects 12. What the secondary cache is, how it is configured, and what you understand about it sessionfactory configuration:TrueOrg.hibernate.cache.EhCacheProvider use: In Java code we need to define before the class, and at the front of the method, before the property. Class is @cache, the object of that class is introduced into the level two cache. *When some of the content is frequently changed infrequently, the content is put into the cache. *Get and load also use level two caching. 13. When using hibernate, in those cases, you will encounter 1+n question, how to solve it? * In a one-to-many/many pairs, often encounter 1+n problem: In the 1-party, found n objects, then need to have n objects associated with the collection, so the original SQL query becomes n+1 Troubleshooting methods: 1Expand the session's Lifecycle filter:PublicvoidDoFilter (ServletRequest servletrequest, Servletresponse servletresponse, Filterchain filterchain)ThrowsIOException, Servletexception {Session session =Hbiutil.getsession (); Filterchain.dofilter (ServletRequest, servletresponse); Hbiutil.closesession (session); HbiUtil.threadLocal.remove (); } ------------------------------------------------------------------------------------------Threadlocal is not a local implementation version of a thread, but rather a thread-local variable. The application of thread-local variables is simple: To provide a copy of the variable's value for each thread that uses a variable, each thread can independently change its own copy without conflicting with the other thread's copy.PublicClassHbiutil {Publicstatic ThreadLocal ThreadLocal =NewThreadLocal ();PublicStaticSession getsession () {//return Factory.opensession ();//In order to solve the problem of n+1 session session =Threadlocal.get ();if (session==Null) {session =Factory.opensession (); Threadlocal.set (session); }ReturnSession }} 2Lazy Loading (delay loading, delayed loading) 14. Hibernate's Cascade property is what the setting is, and under what circumstances, what value should be set. The Cascade Property:(Cascade operation) is when we manipulate an object, and the associated properties of that object do the same. The same action is performed on the property that associates the object when manipulating an object. 15. The function of hibernate's inverse attribute is what, when set, should pay attention to what. Inverse:set after add: inverse= "true"The modification of one party to the other does not lose the relationship use should be noted: inverse set on which side the other side is the host relationship. 16, why is the data cached, what are the benefits of caching, and what data should be cached?In general, starting development does not apply to caching mechanisms * increase the cache, (1): Level two cache, content with low frequency of cached data content if performance requirements are not met. (2) Query Cache *Many systems often add caches at the application level *If some data needs to be taken out frequently, we need to increase the caching mechanism so that we can improve the efficiency of running the program. 17. Oscache, do you understand? What are the benefits of implementing the view layer cache? Oscache is a Oscache cache framework that provides a common caching solution for any Java application with the ability to implement fast memory buffering within existing JSP pages. 18. What is a transaction? Talk about your understanding of him. Things are a sequence of operations that access the database, and the database application system accomplishes the access to the database through the set of things. The proper execution of things makes a database transition from one state to another. The basic concept of a thing: to ensure the integrity of the data, a set of SQL statements that are either executed at the same time or not executed at the same time. A few features: *Atomicity: All operations within a thing are a whole, either all successful or all lost (equivalent to our transfer case, saving and taking money as a whole) *Consistency: When an operation fails inside a thing, all changed data must be rolled back to the pre-modified state *Isolation: The state in which the data is located when the object is viewing the data, or the state in which another concurrent thing modifies it, or the state after which another thing modifies it, and the object does not view the data in the middle state. *Persistence: After a thing is done, its effect on the system is permanent. 19. There are several levels of transaction isolation mechanisms in hibernate that address those issues, which can be problematic when the database system adopts the read Commited isolation level, it causes the concurrency problem of non-repeatable reads and the second class of missing updates, and the optimistic and pessimistic locks can be used in the application to solve the problem. *READ UNCOMMITTED: This is the lowest level of things isolation, reading things does not block reading and writing things, writing things will not block the reading of things, but will block the writing of things. Writing things does not block the reading of things, can read uncommitted data easily cause dirty read. * Read Committed: Solution: Lock the records that have been queried, do not let other things write * repeatable READ: Read things do not block the reading of things, May cause phantom reading problems. Solution: Lock table * serialization: Very low performance, generally not used. 20 if it does not match the field in the Po.
Common problems with Hibernate