1. Talk about your MVC understanding
MVC is the abbreviation for Model-view-controler. That is, the model-view-controller. MVC is a design pattern that forcefully separates the input, processing, and output of an application. Models, views, and controllers in MVC have different tasks.
(1) View: A view is the interface that the user sees and interacts with. The view displays the relevant data to the user and accepts the user's input. The view does not handle any business logic.
(2) Model: The model represents business data and business processing. Equivalent to JavaBean. A model can provide data for multiple views. This improves the reusability of the application
(3) Controller: When the user clicks the Submit button in the Web page, the controller accepts the request and invokes the appropriate model to process the request. The corresponding view is then called according to the result of the processing to display the results of the processing.
MVC process: First the controller accepts the user's request, invokes the corresponding model for business processing, and returns the data to the controller. The controller invokes the corresponding view to display the results of the processing. and presented to the user through a view.
2. Why SSH is used in the project
(1) The use of Struts2 is because Struts2 is based on the MVC pattern, the application is very good layering, so that developers focus on the implementation of business logic; second, struts has a wealth of taglib, such as flexible use, can greatly improve the development efficiency.
(2) Hibernate: Hibernate provides an easy-to-use, efficient object-relational mapping framework for Java applications. Hibernate is a lightweight, durable framework that is rich in functionality.
(3) Use spring: Because Spring is based on the framework of the IOC (inversion of control, reverse control) and AOP architecture multi-layer Java EE system, it does not force you to have to use spring in every layer, because it is well-modularized, Allows you to choose one of its modules according to your needs; IOC makes it easy to implement bean assembly, provides concise AOP, and implements transaction management (Transcation managment), etc.
3. How struts achieves internationalization
The following are examples of the two languages (Chinese, English):
1. Add struts support to your project
2. Edit the Applicationresource.properties file to include the information that you want to use internationalization
Example: Lable.welcome.china=welcome!!!
3. Create an English resource file applicationresource_en.properites
4. Create temporary Chinese resource file Applicationresource_temp.properites example
such as: lable.welcom.china= China welcome you!
5. Encode and convert the temporary Chinese resource file. You can use the MyEclipse plug-in, or under DOS
Perform:
Native2ascii-encoding gb2312 applicationresource_temp.properties
Applicationresource_zh_cn.properties
6. Add struts's bean tag library to the JSP <%@ taglib
Uri= "/web-inf/struts-bean.tld" prefix= "Bean"%>
Display information:
You can define multiple resource bundles in the Struts-config.xml file, and each resource bundle can use the key property to refer to the
The name of the scheduled package.
7. What are the logic tags?
This tag library can be divided into three types: condition, loop, forward/redirect.
(1) Type of condition (not marked is relatively simple)
Logic:empty, Logic:notempty;
Logic:equal, Logic:notequal, Logic:lessthan,
Logic:greaterthan,logic:lessequal, logic:greaterequal;
Logic:present, Logic:notpresent;
Logic:match, Logic:notmatch; Compares two strings for equality, you can compare the start of a string
, the end, or some part of it. Location Property: Specifies that a comparison is started from a position.
(2) Cycle type
Logic:iterate
(3) Forwarding/redirection type
Logic:forward and Logic:redirect
The Logic:forward tag is similar to the jsp:forward tag, but it can use one of the global forward
A Actionforward
For example:
——————————————————————————
The code in the global forward associated with the above:
The logic:redirect tag is similar to the label above, but the method it calls by default is
Response.sendredirect (),
Replaces the above Requestdispatcher.forward (). The biggest difference is that it supports all Html:link
The properties of the tag, so you can specify the request parameter:
Under the MVC framework, these two tags are deprecated and you should choose the next one from the controller
View instead of selecting it from view. Do not use logic tags too much in JSP pages.
8. Action is a single-instance or multiple-instance, why?
Action is a single-instance. When multiple users access a request, only one of the server's memory
The corresponding action class object.
Because when the server first loads the struts configuration file, an action is created, each sending a
Request, the server will first retrieve the appropriate range (request,session) for existence
Such an action instance, if present, uses this instance and, if it does not exist, creates an action instance.
9. What technology is dispatchaction used for?
Dispatchaction is a subclass of Aciton that solves the problem of a request to handle multiple functions.
Ordinary action you can only write the Execute method to handle the business, and you want to use this action to handle multiple any
You have to request parameters to parse and use an IF statement block to handle
To give a small example:
Like the next url:http://localhost:8080/myapp/adduseraction.do.
If you are dealing with this URL with a normal action, you can only execute the inserted
Related actions, if you change the URL:
Http://localhost:8080/myApp/UserAction.do?method=add
You should perform the appropriate action based on the value of the method object, such as having another path
Http://localhost:8080/myApp/UserAction.do?method=delete
This can also be handled with that action, just a little more judgment.
If you use Dispatchaction, it's a lot easier, so dispatchaction still uses the action
a technology.
Struts2.0 's MVC pattern? The difference from struts1.0?
STRUTS2 MVC pattern: When a user submits a user request on a page, the request needs to be submitted to the STRUTS2 control
Processor. STRUTS2 controller According to the processing results,
Decide which page to render to the client.
The biggest difference from Struts1 is the STRUTS2 controller. The STRUTS2 controller is no longer like the Struts1 control
You need to inherit an action parent class, even without implementing
Any interface, the Struts2 action is an ordinary pojo. In fact, Struts2 's action is
A generic Java class that contains the Execute method
The class contains multiple properties that encapsulate the user's request parameters.
What is the configuration file for struts?
Struts-config.xml
12. Please write how struts works.
The processing flow of struts.
First, the initialization of Actionservlet
Actionservlet as the front controller of the struts component due to the corresponding configuration of Web. XML:
0
When a load is applied, it is instantiated and its Init method is called, and the Init method has two main tasks:
1. Load the struts configuration file and create a Moduleconfig object to encapsulate the configuration information
2. Load the resource file and create a Messageresources object to encapsulate the resource file
There are two points to note: if Web. XML has multiple module configurations, it will create multiple Moduleconfig objects and
Messageresources objects, respectively
Struts configuration files and resource files for encapsulating individual modules.
The Moduleconfig objects and Messageresources objects created for each module are stored in the
In the ServletContext, the corresponding genus
The name of the module has the appropriate identity for the
In addition, the Init method initializes the data source and plugin if there is a corresponding configuration
Second, the process of Actionservlet
All requests that are shaped like *.do (according to the configuration in Web. xml) will be submitted to actionservlet and eventually
Will call its Process method
。 The process approach has three main tasks:
1. Obtain the requested module name according to the requested information, and get the request module from the ServletContext
The moduleconfig of the
and stored in the request.
2. According to the module information to obtain the corresponding Requestprocessor object, a module corresponding to a
Requestprocessor object,
The Requestprocessor object associates the Moduleconfig object corresponding to the owning module.
3. Call the process method of the Requestprocessor object to pass request and response as parameters
Hand it to it.
Third, the process of requestprocessor
The main work of the Requestprocessor object's process approach is five steps:
1. Call your own processpreprocess (request, Response) method, which does not make any
Operations, for subclass overrides
Extend its functionality.
2. Obtain the Actionmapping object that matches the requested address, and the Acionmapping object is used to encapsulate a
Configuration information for specific acion
。
3. Obtain the Actionform object based on the configuration information in actionmapping (the object will be cached to
Request or session), and
Populate the form data into Actionform, and then decide whether to validate it based on the configuration of the actionmapping
Actionform, if verified,
The Validate method of the actionform will be called, if the Actionerros object it returns contains
The Actionmessage object represents the validation
Fails, it will turn to the address indicated by the action configuration information input property.
4. If the actionform does not need to be validated or verified by the action that will be created and cached to match the request address
Like, will actionmapping
objects, Actionform objects, request, and response call their execute methods as parameters.
5. Forwards or resets the request based on the Actionforward object returned by the action object's Execute method
to the Actionforward
The address that is encapsulated.
The working mechanism of struts/webwork, what labels it has
The general process of the Struts 2 framework is as follows:
The browser sends requests such as request/mypage.action,/reports/myreport.pdf, and so on.
The core controller Filterdispatcher decides to invoke the appropriate action on request.
WebWork's interceptor chain automatically applies common functionality to the request, such as workflow, validation, or file
Upload and other functions.
The Execute method of the callback action, which first obtains the user request parameter and then executes a certain number of
You can either save the data to the database or retrieve the information from the database. As a matter of fact
Because the action is just a controller, it invokes the business logic component to handle the user's request.
The action's Execute method processing result information is output to the browser, which can be an HTML page, a graph
Like, it can be a PDF document or another document. There are a number of supported view technologies that support both JSP and
Support Velocity, freemarker and other template technology.
Hibernate
1. What is hibernate's concurrency mechanism? How to deal with concurrency problems?
Hibernate concurrency mechanism:
A, Hibernate session object is non-thread safe, for single request, single session, single work
Unit (that is, a single transaction, a single thread), which is usually used only once,
And then throw it away.
If a session instance allows sharing, those that support concurrency, such as HTTP
Request,session beans will cause resource contention to occur.
If you have hibernate session in the HTTP session, you may have synchronous access to HTTP
Session. As long as the user clicks the browser's "refresh" fast enough,
Will cause two concurrently running threads to use the same session.
b, multiple transactions concurrently access the same piece of resources, may cause the first kind of lost updates, dirty read, Phantom Read, not
Repeat read, the second category loses the update a series of questions.
Solution: Set the transaction isolation level.
Serializable: Serialization. Highest Isolation Level
REPEATABLE READ: Repeatable reading
Read Committed: Committed data read
READ UNCOMMITTED: Uncommitted data reads. Worst Isolation Level
Set locks: optimistic and pessimistic locks.
Optimistic Lock: Use version number or timestamp to detect update loss, set optimistic-in the map
lock= "All" can implement version checking without a version or timestamp attribute mapping, at which point
Hibernate compares the status line-level pessimistic lock for each field of a row of records: Hibernate always uses the number
The object is never locked in memory, according to the locking mechanism of the library! As long as you specify the isolation level for the JDBC connection,
Then let the database to get everything done. Class Lockmode defines the different locks required for hibernate
Level: Lockmode.upgrade,lockmode.upgrade_nowait,lockmode.read;
2. Several exceptions that often occur in Hibernate and spring
Org.springframework.beans.factory.BeanCreationException:
Error creating Bean with Name ' sessionfactory ' defined in ServletContext
Resource [/web-inf/applicationcontext.xml]:
Initialization of Bean failed; Nested exception is
org.hibernate.MappingException:Repeated column in mapping for entity:
Com.xindeco.myregister.pojo.MyRegisterInfo column:
Password (should is mapped with insert= "false" Update= "false")
Cause of Error: Password and Repassword correspond to the password column in the database table, while
Both update and insert are set to true. The XML file is as follows:
Type= "Java.lang.String"
Update= "true"
Insert= "true"
Access= "Property"
column= "Password"
Length = "32"
/> type= "Java.lang.String"
Update= "false"
Insert= "false"
Access= "Property"
column= "Password"
Length = "32"
/>
WORKAROUND: Set Repassword Insert and update to FALSE.
Org.springframework.beans.factory.BeanCreationException:
Error creating Bean with Name ' sessionfactory ' defined in ServletContext
Resource [/web-inf/applicationcontext.xml]:
Initialization of bean failed;nested exception is
Org.hibernate.PropertyNotFoundException:Could not find a getter for ID
In class
Error reason: The ID in Hibernate's mapping file is uppercase, and the ID in Pojo class is lowercase
Workaround: Either change the ID in the Pojo class to uppercase or the ID in the Hibernate mapping file
Called lowercase.
3. Hibernate's connection to JDBC
Hibernate is a lightweight package for JDBC, including JDBC's connection to the database (with
The Hibernate.property configuration file implementation of course essentially encapsulates the JDBC forname),
and query, delete and other code, all with the object-oriented thinking with code, hibernate through HBM
The configuration file associates the fields of the Po class with the fields of the database, such as the database ID,
In the PO class is the Pravite Long ID; Public long getId ();p ublic setId (long id);
Then the HQL statement is also object-oriented, and its query statement is not querying the database but querying the class, these real
Now the magic is the XML file, in fact hibernate= encapsulated Jdbc+xml file
4. Hibernate's contact with spring
Some of the objects in Hibernate can be managed for spring, allowing the spring container to create a
Some object instantiation. For example: Sessionfactory,hibernatetemplate and so on.
Hibernate was originally a database operation, placed on the DAO layer, and spring gives the business layer a way to define
Transaction, the business layer calls the DAO layer method, and it's good to add hibernate operations to the transaction.
5. What is the paging mechanism that hibernate comes with? If you do not use Hibernate's own paging,
What is the way of paging?
1. Hibernate comes with paging mechanism: After getting the session object, get the query from the session
Like. With Query.setfirstresult (): Sets the first row of data to be displayed,
Query.setmaxresults (): Sets the last row of data to display.
2, do not use hibernate comes with the page, you can use the SQL statement paging,
Example: 5: Records displayed for each page, 2 for the current page: SELECT * Top 5 from table where tabId
Not in (select TabId Top (2-1), from table);
6. Hibernate three persistent state of the object, and give an explanation?
It is not clear that there are three persistent states for Hibernate objects, only three states of Hibernate objects are known, the following
Have introduced.
7. What is returned by a one-to-many configuration file in hibernate?
A one-to-many configuration file in Hibernate is mapped to two tables, and the relationship between them is a pair
A lot of.
For example: a relationship between a student and a classes table. A student can only be a class, a class can have
Multiple students.
8. What is the difference between update () and Saveorupdate ()?
Update () and saveorupdate () are used for state management of the PO that crosses the session.
The object that the update () method operates on must be a persisted object. In other words, if this object is in the database
You cannot use the update () method if it does not exist.
The object that the Saveorupdate () method operates on can be either persisted or made non-persisted to the
Like. If the persisted object calls Saveorupdate (), it will
Updates the objects in the database, or save to the database if the object is not persisted by using this method.
9. How to convert between three states of Hibernate
When an object is a save () by an instantaneous state (Transient), it becomes persisted.
When we store objects in the session, we actually save a copy of the session map,
That is, it's got a copy in the cache, and then it's stored in the database, in the cache.
Long objects (persistent).
Session a close (), its cache is also closed, the entire session will be invalidated,
At this point, the object becomes a Free State (Detached), but it still exists in the database.
When the Free State (Detached) is update (), it becomes a persistent state (persistent).
When the persistent state (persistent) Delete () becomes transient (Transient),
At this point, there are no records in the database that correspond to it.
Why does hibernate deny connectivity and server crashes? Minimum of 5 Write
1. DB Not open
2. There may be a problem with the network connection
3. The connection configuration is wrong.
4. Is the driver's driver,url all right?
5. Lib to add the appropriate driver, the data connection code is wrong
6. There may be a problem with the database configuration
7. There are too many current joins and the server has a limited number of visitors.
8. The corresponding port of the server is not open, that is, it does not provide the corresponding service
A. Hibernate introduction
Hibernate is an open source object-relational mapping framework that is very lightweight for JDBC
Object encapsulation, which allows Java programmers to manipulate the database at will using object programming thinking.
Hibernate can be used in any application where JDBC is used, either in the Java client program or
Can be used in servlet/jsp Web applications, the most revolutionary is that hibernate can be applied
EJB's Java EE Architecture replaces CMP and completes the task of data persistence.
Hibernate has a total of 5 core interfaces, namely: Session, Sessionfactory,
Transaction, query, and configuration. These 5 core interfaces will be used in any development. Wildcard
These interfaces allow access to persistent objects and transaction control. The following five
A core interface is described separately.
? Session Interface: The session interface is responsible for performing crud operations on persisted objects (crud tasks are
Complete the communication with the database, including a lot of common SQL statements. )。 But it's important to note that the session
As non-thread-safe. At the same time, Hibernate's session differs from the HttpSession in JSP applications.
When the term "session" is used, it actually refers to the session in Hibernate and will later
The Httpsesion object is called the user session.
? Sessionfactory interface: The Sessionfactroy interface is responsible for initializing hibernate. It acts as a number
The agent that stores the source and is responsible for creating the Session object. The factory model is used here. It is important to note that
Sessionfactory is not lightweight, because in general, a project usually requires only one
Sessionfactory is enough, when you need to manipulate multiple databases, you can specify one for each database
Sessionfactory.
? Config interface: Configuration interface is responsible for configuring and starting hibernate, creating
The Sessionfactory object. During Hibernate startup, an instance of the configuration class first
Locate the mapped document location, read the configuration, and then create the Sessionfactory object.
? Transaction interface: The transaction interface is responsible for transaction-related operations. It is optional, developed
People can also design and write their own underlying transaction-processing code.
? Query and Criteria interface: query and Criteria interfaces are responsible for executing various database queries. It can be
To use either the HQL language or the SQL statement.
Hibernate PRIMARY Key Introduction
Assigned
The assigned method generates a primary key value by the program and will throw an exception if it is specified before save ()
Feature: The generated value of the primary key is determined entirely by the user, regardless of the underlying database. User needs to maintain primary key
Value, specify the primary key value before calling Session.save ().
Hilo
Hilo uses a high-low algorithm to generate the primary key, and the low-level algorithm uses a high value and a low
The two values obtained by the algorithm are stitched together as the unique primary key in the database. The Hilo method requires an additional number
The source of high values is provided by the library tables and fields. By default, the table used is
Hibernate_unique_key, the default field is called Next_hi. Next_hi must have a record or else
An error will occur.
Features: Additional database table support is required to ensure the uniqueness of the primary key in the same database, but
It is not possible to guarantee the uniqueness of primary keys between multiple databases. The Hilo primary key generation method is maintained by Hibernate,
The Hilo approach is independent of the underlying database, but you should not manually modify the values of the tables used by the HI/LO algorithm, otherwise
Causes the primary key to repeat the exception.
Increment
The increment method generates a new primary key value in a way that automatically increases the primary key value, but requires the underlying number
According to the library's support sequence. such as ORACLE,DB2 and so on. Need to include in the mapping file Xxx.hbm.xml
The setting of the increment marker.
Features: Maintained by hibernate itself, suitable for all databases, not suitable for multi-process concurrent updates
database, suitable for a single process to access the database. cannot be used in a clustered environment.
Identity
Identity was supported automatically by the underlying database, with different primary keys for different databases
Growth patterns.
Features: Related to the underlying database, requires the database to support identity, such as MySQL is
auto_increment, SQL Server is identity, supported databases are MySQL, SQL
Server, DB2, Sybase, and Hypersonicsql. The identity does not require hibernate and user intervention,
Easier to use, but it's not easy to migrate programs between different databases.
Sequence
Sequence requires the underlying database to support sequence methods, such as Oracle database, etc.
Features: The support sequence of the underlying database is required, the database supporting the sequence has DB2, POSTGRESQL,
Qracle, sapdb, etc., migrate programs between different databases, especially from databases that support sequences to non-
Databases that support sequences need to modify the configuration file
Native
The native primary key generation method automatically chooses identity, Sequence,
Hilo Primary Key Generation method
Features: Depending on the underlying database, different primary key generation methods are used. Since Hibernate will root
The underlying database is mapped in different ways, so it's easy to transplant, and if you use multiple data in your project
Library, you can use this method.
Uuid
The UUID uses the 128-bit UUID algorithm to generate the primary key, which guarantees the uniqueness of the primary key under the network environment, and
can guarantee the uniqueness of the primary key under different databases and different servers.
It can guarantee the uniqueness of the primary key in the database, and the generated primary key occupies more storage space.
Foreign GUID
Foreign is used in a one-to-one relationship. The GUID primary key generation method uses a special algorithm to ensure that the raw
Cheng's uniqueness, support for SQL Server and MySQL
Brief introduction to the role of several packages in Hibernate source code
Net.sf.hibernate.* the class of the package is basically the interface class and the exception class
Implementation class of Net.sf.hibernate.cache.* JCS
net.sf.hibernate.cfg.* configuration file Read class
Net.sf.hibernate.collection.* Hibernate Collection Interface implementation classes, such as
List,set,bag and so on, hibernate is going to write its own collection interface implementation class to support
Lazy Loading
net.sf.hibernate.connection.* provider of several database connection pools
Net.sf.hibernate.dialect.* supports a variety of database features, and each dialect implements a class generation
Table A database that describes the data types and other features supported by the database, such as whether there are
AutoIncrement, whether there is sequence, whether there is paging SQL, etc.
Examples of net.sf.hibernate.eg.* hibernate documentation
Net.sf.hibernate.engine.* the class function of this package is relatively scattered
Net.sf.hibernate.expression.* HQL Supported expressions
Net.sf.hibernate.hq.* HQL Implementation
net.sf.hibernate.id.* ID Generator
Net.sf.hibernate.impl.* the most core package, some important interfaces of the implementation class, if
Session,sessionfactory,query, etc.
Net.sf.hibernate.jca.* JCA Support, the session is packaged as a JCA-enabled interface implementation class
net.sf.hibernate.jmx.* I do not know jmx, only the JMX is used to write the app server
The hypervisor, presumably the implementation of the JMX partial interface, allows app server to manage through the JMX interface
Hibernate
Net.sf.hibernate.loader.* is also a very central package, mainly the generation of SQL statements
net.sf.hibernate.lob.* Blob and CLOB support
net.sf.hibernate.mapping.* Properties for HBM files
Meta implementation of Net.sf.hibernate.metadata.* PO
Net.sf.hibernate.odmg.* ODMG is an ORM standard, this package is ODMG standard implementation class
Net.sf.hibernate.persister.* core package for mapping between persistent objects and tables
Net.sf.hibernate.proxy.* Proxy and lazy loading support
Net.sf.hibernate.ps.* The package is preparedstatment Cache
net.sf.hibernate.sql.* Generating a JDBC SQL statement package
Net.sf.hibernate.test.* test class, you can use JUnit to test hibernate
Net.sf.hibernate.tool.hbm2ddl.* generating DDL with HBM configuration files
net.sf.hibernate.transaction.* Hibernate Transaction Implementation class
Net.sf.hibernate.type.* hibernate defines the data type of the persisted object's properties
Net.sf.hibernate.util.* some tools, the role of a more scattered
net.sf.hibernate.xml.* XML Data Binding
14. Cache Management
Hibernate provides a level two cache, and the first level of cache is session-level caching, which is
The cache that belongs to the transaction scope. This level of caching is managed by hibernate and is generally not required
The second level of caching is the sessionfactory level of cache, which is a process-wide or cluster-
The cache of the enclosure. This level of caching can be configured and changed, and can be dynamically loaded and unloaded.
Hibernate also provides a query cache for query results, which relies on a second-level cache.
1. Primary cache and level two cache comparison: first level cache second-level cache holds data in the form of
The range of transaction scopes for the bulk data cache of an interconnected persisted object object, with each transaction having a separate
The first level of cache process scope or cluster scope, the cache is shared by all transactions within the same process or cluster
Enjoy concurrent access policies because each transaction has a separate first-level cache, there is no concurrency problem, no
Need to provide concurrent access policy because multiple transactions access the same data in the second level cache, it is necessary to mention
For appropriate concurrent access policies to ensure that the specific transaction isolation level data expiration policy does not provide data
Expiration policy. Objects in the first-level cache never expire unless the application explicitly empties the cache or
Clearing a specific object must provide a data expiration policy, such as the maximum number of objects in the memory-based cache,
The maximum time allowed for an object to be in the cache, and the maximum idle time that the object is allowed to be in the cache physical
Storage media memory memory and hard disk. object's bulk data is first stored in the underlying cache, when the memory
When the number of objects in the data expiration policy reaches the specified limit, the remaining objects are written to the hard disk-based
The cache. The implementation of the cached software in Hibernate session contains the implementation of the cache by the
Provided by the three Parties, hibernate only provides a cache adapter (Cacheprovider). Used to plug a specific cache into
The components are integrated into hibernate. Caching is enabled as long as the application passes the session interface to perform the guaranteed
Database data is stored, updated, deleted, loaded, and queried, Hibernate enables the first-level
Data in the database is copied to the cache in the form of objects, for bulk updates and bulk delete operations.
If you do not want to enable the first level of caching, you can bypass the Hibernate API directly through the JDBC API to
Execution refers to an action. Users can configure a second-level cache on the granularity of a single collection of classes or classes. If the class
Instances are read frequently but rarely modified, you can consider using a second level cache. Only for a class or collection
A second-level cache is configured, and Hibernate adds its instance to the second-level cache at run time. Use
Cache in the first level cache physical media is memory, due to limited memory capacity, you must pass the
The number of objects that are loaded when the retrieval policy and retrieval methods are limited. The Evit () method of the session can be explicitly
Empty the cache for specific objects, but this method is not recommended. The second-level cache of physical media can be internal
Storage and hard disks, so the second-level cache can hold a large amount of data, the data expiration policy
The Maxelementsinmemory property value can control the number of objects in memory. Managing second-level cache primary Packages
Two aspects: Select a persistence class that requires a second-level cache, and set the appropriate concurrency access policy: Select
Cache adapter, set the appropriate data expiration policy.
2. First level cache management: When the application calls the session's save (), update (),
Savaeorupdate (), get (), or load (), and a list (), iterate (), or a call to the query interface
Filter () method, if the corresponding object does not exist in the session cache, Hibernate will
The object is added to the first-level cache. When the cache is cleaned, hibernate changes depending on the state of the object in the cache
Update the database synchronously. Session provides the application with two ways to manage the cache:
Evict (Object obj): Clears the persisted object specified by the parameter from the cache. Clear (): Empty cache
All persisted objects in the.
3. Management of Level two cache:
The general process for 3.1. Hibernate's level two cache strategy is as follows:
1) When a condition is queried, always issue a SELECT * FROM table_name where ....
(select all fields) such SQL statements query the database and get all the data objects at once.
2) Put all the obtained data objects into the second level cache based on the ID.
3) When hibernate accesses the data object according to the ID, the first cache is checked from the session level;
Not found, if a level two cache is configured, then from the level two cache, check, and then query the database, the
The result is placed in the cache by ID.
4) Update the cache while deleting, updating, and adding data.
Hibernate's level Two cache policy is a cache policy for ID queries, and for conditional queries
No effect. To do this, Hibernate provides query Cache for conditional queries.
3.2. What kind of data is suitable for storage in the second level cache? 1 rarely modified data 2 are not
Very important data, allowing for occasional concurrent data 3 data that will not be accessed concurrently 4 reference data,
Refers to the constant data of supply reference, it has a limited number of instances, its instances will be many other classes of the real
Examples are rarely or never modified.
3.3. Not suitable for storing data in a second level cache? 1 frequently modified data of 2 financial data,
Data that is shared with other apps is never allowed to occur concurrently with 3.
3.4. Common cache plug-in Hibernater's level two cache is a plug-in, here are a few common
Cache plug-in:
EhCache: As a process-wide cache, the physical media that holds the data can be memory or hard disk,
Provides support for Hibernate's query caching.
Oscache: As a process-wide cache, the physical media that holds the data can be memory or hard disk,
Provides a rich cache data expiration policy that provides support for hibernate query caching.
Swarmcache: Can be used as a cluster-wide cache but does not support Hibernate's query cache.
JBossCache: Can be used as a cluster-wide cache, support transactional concurrency access policies,
Hibernate's query cache provides support.
3.5. The main steps for configuring level two caching:
1) Select the persistence class that requires a level two cache, and set its concurrent access policy for the named cache.
This is the most serious step to consider.
2) Select the appropriate cache plug-in, and then edit the plugin's configuration file.
Spring
1. What do you usually do with spring?
Control reversal IOC AOP
2. Which method of the class in spring can be used to get the bean
3. What is Spring? Talk about your opinion in detail according to your understanding.
Objective: To solve the complexity of enterprise application development
Function: Use basic JavaBean instead of EJB, and provide more enterprise application function
Scope: Any Java application
In short, spring is a lightweight control inversion (IoC) and aspect-oriented (AOP) container framework.
Lightweight-Spring is lightweight, both in terms of size and overhead. The complete Spring Framework can
Published in a jar file with a size of more than 1MB. and the processing overhead required by spring is negligible.
Of In addition, spring is non-intrusive: Typically, objects in spring applications do not depend on spring's
Specific class.
Control reversal--spring facilitates loose coupling through a technique called inversion of Control (IoC). When you should
With the IOC, the other objects that an object relies on are passed in passively, not the object
Create or find dependent objects yourself. You can think of the IOC as opposed to Jndi--not objects looking from the container
Dependency, instead the container actively passes the dependency to it when the object is initialized with unequal object requests.
Faceted--spring provides rich support for aspect-oriented programming, allowing the industry to separate applications
System-level services (such as auditing (auditing) and transaction () management) for cohesive
Hair The Application object only implements what they should do-complete the business logic-that's all. They are not responsible for (very
Awareness) Other system-level concerns, such as log or transaction support.
The container--spring contains and manages the configuration and life cycle of the Application object, in this sense it is a
container, you can configure how each of your beans is created-based on a configurable prototype
(prototype), your bean can create a separate instance or generate a new one each time it is needed
And how they relate to each other. However, spring should not be confused with the traditional heavyweight
EJB containers, they are often bulky and unwieldy and difficult to use.
Framework--spring can be used to configure and assemble simple components into complex applications. In spring,
Application objects are declaratively combined, typically in an XML file. Spring also provides a number of basic
Functions (transaction management, persistence framework integration, etc.), leaving the development of application logic to you.
All of these features of spring enable you to write cleaner, more manageable, and easier-to-test generation
Code. They also provide basic support for the various modules in spring.
4. How the project reflects the section programming in spring, the distance description.
Aspect-oriented programming: The main point is to cross-cut a focus, and a point of concern is modularized into a tangent plane. In tangent
A notice (Advice) and a pointcut (Pointcut) are declared on the Notice: Refers to a particular connection in a plane.
Contact (represents the execution of a method.) By declaring a parameter of type Org.aspectj.lang.JoinPoint
Number allows the body portion of the notification (Advice) to obtain connection point information. ) to perform the action on the. Notification of the fixed
The method to be inserted is justified. Pointcut: The content of a pointcut is an expression that describes what objects need to be
Which methods are defined in the INSERT notification.
The most common areas of spring that are used in projects are: declarative transaction management.
A. Define a transaction manager
B. Configure transaction attributes (equivalent to declaration notifications). Transactions are typically defined on some methods of the class of the business layer)
C, configure which classes of which methods require a configuration transaction (equivalent to a pointcut. is generally a method of business class)
6. How spring acts as a binder in the project
1. Use spring's IOC (control inversion or dependency injection) in the project to explicitly define the component interfaces (such as
Userdao), developers can independently develop individual components and assemble them based on dependencies between components
(Useraction relies on userbiz,userbiz relies on Userdao) to run, very good
Struts (Action) is combined with hibernate (the DAO Implementation).
2. Spring's transaction management set hibernate to the operation of the database transaction configuration.
7. How spring transactions are configured
Declarative transaction configuration for spring:
1.
class= "Org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
/web-inf/classes/hibernate.cfg.xml
2. Configure the transaction manager
class= "Org.springframework.orm.hibernate3.HibernateTransactionManager" >
8. Transaction there are several implementations (transaction processing) (Spring)
In spring, there are two main ways in which transactions are handled
(1) Code Control transactions
Introduce a new template class in the program that encapsulates the functionality of transaction management
(2) Parameter configuration control transaction, add a transaction agent in Application-context.xml
(userdaoproxy) configuration
Java SSM face question