Q.1 The life-cycle of a Persistent Object.
Ans. The total number of states traversed by an object to reach its initial states is known as the life-cycle of the object.
- Transience
- Persistence
- Detachment
Transient is the state of an object when it is not associated with any database. Any object instantiated using the new operator in this state. Since they are not associated with any row of a table,they are destroyed.Transient objects don't come under context of a transaction. That means if the values of a transient object are updated, calling the rollback() method doesn't undo the changes made to the object.
Persistent state :: An object is said to be in a persistent state when it has a database identity. An object having a database identity simply means that the identity of the object has been set using the primary key value of the table row it represents. In short, when the identity of the object containts the value of the primary key of the table row it reaches a persistent state. To make any transient object persistent, the save method of the Persistence manager has to be called.The most important characteristic feature of an object in the persistent state is that it takes part in transactional activities.
Even in the persistent state, the object says in different states. Until the commit() method of transaction management is called with the objects as a parameter, the object remains in the new state.Whenever any value held by persistent object changes, the object becomes dirty.This state is not visible to the application. The trick used by Hibernate is known as Transparent-Level Write-Behind.The framework does this by delaying the synchronization of the object to the database table and then hides the details from the application.
This feature leads us to another feature where only those column values are updated which are modified. To do so the dynamic-update attribute to the
Detached State :: In hibernate, when the transaction completes by calling the close() method on the Session object, the instance of persistence class lose their association with the Persistence manager. Thus the detached state is attained. In this state the object is no longer under the management of hibernate. Though the Persistence or Transaction manager is no longer managing the object, it still contains the persistent data (data contained in the row of the corresponding table).
Q.2 what is the difference between JSP forward and Servlet forward methods?
Ans. JSP forwards forwards the control to another resource available in the same webapplication on the same container, where as Servelet container forward forwards the control to another resource available in the same web application or different web application on the same contrainer.
Q.3 What is the difference between include directive and jsp:include action?
Ans. jsp:include tag includes the jsp during runtime whereas the <@ include> the specified jsp during compilation time. If we modify a jsp that is included in <@include> tag then the change will not be reflected since we are not compiling, the jsp with <@include> whereas it gets reflected when using jsp:include
Q.4 How I can implement a thread-safe JSP page?
Ans. We can make our JSPs thread-safe by having them implement the SingleThreadModel interface.This is done by adding the directive <%@ page isThreadSafe="false"%>within our JSP page.
Q.5 What are the implicit objects in JSP & difference between them?
Ans. There are 9 implicit objects defined in JSP are: application, config, exception, out, page, pageContext, request, response and session.
The main difference between these objects lies in their scope and the data they handles.
1. application interface (javax.servlet.ServletContext) Refers to the web application's enviornment.
2 Session interface (javax.servlet.http.HttpSession) Refers to the User's session.
3 request interface (javax.servlet.http.HttpServlet.Request) Refers to the current request page.
4 response interface (javax.servlet.http.HttpServlet.Response) Refers to the current response to the client.
5 out class (javax.servlet.jsp.JspWriter) Refers to the output stream for the page.
6 page class(javal.lang.Object) Refers to the page's servlet instance
7 pageContext class (javax.servlet.jsp.PageContext) refers to the page's enviornment.
8 config interface (javax.servlet.ServletConfig) Refers to the servlet's configuration
9 exception class (java.lang.Throwable) used for error handling.
0 comments
Post a Comment