Struts + spring + hibernate interview questions

Source: Internet
Author: User

1. Is action thread-safe? If there is no way to ensure the thread security of action? If yes, explain the reason
Action is NOT thread-safe. Thread security can be ensured without declaring class variables. Because only one action instance exists, all threads share variables.

Declare local variables, or expand requestprocessor to create an action each time, or use scope = "prototype" in spring to manage

2. MVC: analyze how struts implements MVC.
M: JavaBean or composed of EJB components or pojo
C: Implement actionservlet and action
V: A group of JSP files and their tags.

3. Role of several key objects in struts (Role of several key objects)
Action: controller class, actionform: form object, dynavalidatorform: dynamic form, actonmapping: information about the action node in the configuration file ......

4. Introduce the concepts of AOP and IOC and how to apply them in spring.
AOP: For Aspect-Oriented Programming, IOC: dependency injection; declarative and programmatic transactions are positive and common

5. What data query methods does hibernate use?
Hql query, SQL query, and QBC condition Query

6. Differences between load () and get ()
Hibernate considers the load method to exist in the database, so you can safely use the agent to delay loading. Load () supports delayed loading by default, you can query the database only when other properties of the object are used. However, if the record does not exist in the database, you can only throw the objectnotfoundecception exception; the load method throwing exception refers to throwing an exception when the data of this object does not exist in the database, rather than when the object is created. Since the session cache is a very cheap resource for hibernate, we will first check the session cache during load to see if the object corresponding to this ID exists, create a proxy if it does not exist (query level-1 Cache during load, and create a proxy if it does not exist ).
Get () First searches for data in the first-level cache. If not, it searches for data in the second-level cache. If not, it searches for the database. If not, null is returned. For the get method, hibernate must obtain real data; otherwise, null is returned.

Simply put, if the data cannot be queried, load () will throw an exception, and get () will return null.

7. Talk about hibernate's delayed loading and opensessioninview
Delayed loading should be within the range of sessions and re-loaded when used. opensessioninbiew writes a filter on the web layer to open and close sessions, in this way, the session is always on during a request process, ensuring the delay of loading in the session.

8. How can spring transactions be performed? Let's talk about the isolation level and Propagation Behavior of spring transactions.
Declarative and programmatic transactions
Isolation level:
-Default: use the default database isolation level
-Read_uncommitted: there will be dirty reads, and repeated reads and Phantom reads are not allowed.
-Read_committed: Repeated read and phantom read will appear.
-Repeatable_read: phantom read will appear.
-Serializable is the safest, but the most expensive, with extremely serious performance impact.
And propagation line:
-If required has a transaction, it is integrated into the transaction. If it does not exist, the transaction is created.
-If supports has a transaction, it is integrated into the transaction. If it does not exist, no transaction is created.
-If a mandatory transaction exists, the transaction is merged. If the transaction does not exist, an exception is thrown.
-Requires_new: always creates new transactions.
-Not_supported: if a transaction exists, the transaction is suspended and non-transaction operations are continuously performed.
-Never always executes non-transactions. If the current transaction exists, an exception is thrown.
-Nested embedded transactions

9. Differences between update () and saveorupdate () in hibernate.

Saveorupdate () Does the following:
If the object is already persistent in this session, do not do anything
If another object associated with this session has the same persistent identifier (identifier), an exception is thrown.
If the object does not have the identifier attribute, call save ()
If the object's persistent identifier (identifier) indicates that it is a new instantiated object, it calls save ()
If the object contains version information (via <version> or <timestamp>) and the value of the version attribute indicates that it is a new instantiated object, save () It. Otherwise, update () is the object.

10. Spring provides good support for a variety of ORM frameworks. It briefly describes how to use hibernate in spring and integrates transaction management. (Common)

Gethiberantetemplate provides methods such as Save, update, delete, and find.
To put it simply: If a declarative transaction is configured, when various methods of gethibernatetemplate are executed, the transaction will be automatically loaded if no transaction is configured, the above operations will not be actually synchronized to the database, unless hibernate's autocommit = true is configured

8. How can spring transactions be performed? Let's talk about the isolation level and Propagation Behavior of spring transactions.
Spring transactions are in two forms: declarative transactions and programmatic transactions. Spring provides a transaction interface called the paltformtractionmanager interface. Spring implements different implementations for different transactions and hibernate transactions.
Implementation of hibernatetractionmanager, jdbctractionmanager for JDBC, datasourcetractionmanager and jdotractionmanager. The platformtractionmanager interface provides three methods to obtain, commit, and roll back transactions.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.