How does hibernate work and why should I use it?Principle:1. Read and parse the configuration file2. Read and parse mapping information, create Sessionfactory3. Open Sesssion4. Create Transaction Transation5. Persistent operation6. Commit a transaction7. Close session8. Close SesstionfactoryWhy to use:1. The code for JDBC access to the database is encapsulated, which greatly simplifies the tedious repetitive code of the data access layer.2.
Hibernate from the introduction to the Master (a) JDBC introduction, we mainly introduced the JDBC and the use of instructions, this time we do a hibernate simple example, through this example to compare hibernate and JDBC, to understand the advantages of
Today, when I was learning Shiro, I built a springmvc+spring+hibernate integration framework, and then I made an error when I ran the one-many,many-one mapping relationship with lazy loading.
Could not initialize proxy-no the session and then went on the internet to find data, which means that since Hibernate and spring
. AbstractPlatformTransactionManager. doGetTransaction ()AndOrg. springframework. transaction. support. AbstractPlatformTransactionManager. doBegin (Object, TransactionDefinition)
That is to say, these key tasks must be implemented by the specific transaction manager. For the hibernate Transaction Manager, the method to obtain the transaction object is as follows:
The procedure for starting a transaction is as follows:
The above is the code about th
This blog will take you through a simple example to learn the Hibernate project.1. Create a Java project 2. Create user Library and join the dependency package* Hibernate_home/lib/*.jar* Hibernate_home/hibernate3.jar* Added database driver (MySQL driver)Specific steps refer to my previous blog: "Hibernate advanced" How to add jar packages in MyEclipse3, provide h
This configuration is the spring, SPRINGMVC, hibernate three modules are configured separately, cross-reference! Hibernate connection configuration using the. properties fileWeb. XML configuration Spring.xml Springmvc.xml Spring_hibernate.xml Congfig.properties (Hibernate connection Configuration)#MySQL hibernate.
directory for Lucene (you can give the absolute path, because I am a Linux system, so there is no drive letter), of course, only valid for hibernate, if you skip hibernate direct operationsLucene, this directory is useless
Configuration in Spring:People familiar with spring + hibernate should be familiar with this con
automatically update the table structure, even if the table structure changed, but the table in the row still exists will not delete the previous row. Note that when deployed to the server, the table structure is not immediately established, is to wait for the first time the application will be run.Validate:Each time the hibernate is loaded, the validation creates the database table structure, which only compares to tables in the database, does not c
Label:Integrate hibernateIntegrate what?
An IOC container to manage Hibernate's sessionfactory
Let hibernate use a declarative transaction on spring
?Add Hibernate driver Package firstNew Hibernate.cfg.xmlConfigure basic properties for Hibernate
The data source needs to be configured in the I
to many-to-many complex relationships.
2. How does hibernate delay loading?
1. Implementation of hibernate2 delayed loading: a) object B) Collection)
2. hibernate3 provides the property's delayed Loading Function
When hibernate queries data, the data does not exist in the memory. When the program really operates on the data, the object exists in the memory, and the loading is delayed, it saves the server m
Document directory
How does hibernate work and why?
How does hibernate delay loading?
In hibernate, how does one implement the relationship between classes? (For example, one-to-many and many-to-many relationships)
Let's talk about the cache mechanism of hibernate.
With the application of the orm framework, development is more object-oriented, and there is no need to design a database specifically, instead of writing entities and object ing.
Therefore, entity writing is a very basic and important task. Do not drag your development work back when you do it. For example, to verify the validity of data, we are used to doing it in action or controller. In fact, this work can be done in advance in entity.
JSR303Bean
queries data, the data does not exist in the memory. When the program actually operates on the data, the object exists in the memory, and the loading is delayed, it saves the server memory overhead and improves the server performance.
3. How does one implement the relationship between classes in hibernate? (For example, one-to-many and many-to-many relationships)
The relationship between classes is mainly
propagation_required,
-Com. example. exception. facadeexception
propagation_required, readonly
propagation_required, readonly
Once the transaction attributes are specifi
doesn't mean that spring and struts integrateIt's a spring HelloWorld.Next, we need to add a listener to the Web. xmlNew Web. xmlclass>org.springframework.web.context.contextloaderlistenerclass> class>org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilterclass> /*And then join in a Struts2-spring-plugin-2.1.8.1.jarChange the class property of the
perform configuration-based transaction processing. An Interceptor configuration removes all your troubles.
3. Dao Layer Use the hibernate API encapsulated by spring to make hibernate slim and establish a relationship with the upper layer through spring.
4. Finally, let's talk about the Po of hibernate.You can choose
Project directory structure:
Project StructureStep 1: Prepare the jar package
The above are all jar packages required by springmvc + hibernate.Copy all jar packages to the lib directory of the web project.Step 2: configure the file
Copy and modify files From HibernateFirst, go to the ETC folder from the project folder in Hibernate and copy the two files to the classpath folder,
Figure 2-1
## HypersonicSQLdataSource.password=dataSource.username=root
Originally wanted to write down spring+springmvc+hibernate integration of the article temporarily do not write the direct attached source code, there is a need for direct download to see it. There are previous articles in the SPRINGMVC source code before the article is simply said to build the environment to access the page successfully. This source code has simulated additions and deletions and file upload
level Cach E provider, Hibernate-infinispan, for example, are available in the classpath).The Hibernate.cfg.xml configuration needs to be added:Org.springframework.beans.factory.BeanCreationException:Error creating Bean with Name ' sessionfactory ' defined in Class path resource [Resource/applicationcontext.xml]: Invocation of Init method failed; Nested exception is Java.lang.noclassdeffounderror:org/slf4j
SpringMVC + Spring + Hibernate, springmvchib.pdf
Although Strusts2 + Spring + Hibernate is the mainstream WEB development framework, SpringMVC is widely used by more and more people!
Here is a small example of SpringMVC + Spring +
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.