Hi again,I reran the query in a new window with the dufealt behavior of read committed and seperatley ran the update statement and it does return two different results.My mistake was running different implementations of the query 1 from the same window. Thanks again,it works.
What is the use of "implements Serialization" for POJO while using Hibernate
For so many days I have a question what is exactly use to implements Serialization for Hibernate POJO.
Using "implements Serialization" we can make objects persist. That's why while using hibernate will make POJO's Serializable to make object persists across session.
Java has a built-in persistence mechanism: Serialization provides the ability to write
a graph of objects (the state of the application) to a byte-stream, which may then
be persisted to a file or database. Serialization is also used by Java’s Remote
Method Invocation (RMI) to achieve pass-by value semantics for complex objects.
Another usage of serialization is to replicate application state across nodes in a
cluster of machines.
Why not use serialization for the persistence layer? Unfortunately, a serialized graph of interconnected objects can only be accessed as a whole; it’s impossible to retrieve any data from the stream without deserializing the entire stream. Thus, the resulting byte-stream must be considered unsuitable for arbitrary search or aggregation. It isn’t even possible to access or update a single object or subgraph independently. Loading and overwriting an entire object graph in each transaction is no option for systems designed to support high concurrency.
Clearly, given current technology, serialization is inadequate as a persistence mechanism for high concurrency web and enterprise applications. It has a particular niche as a suitable persistence mechanism for desktop applications.
POJO should implement Serializable. As a best practice, to work with clustered application server environment, any object kept in Servlet HttpSession should be Serializable. POJO is this kind of object.
It's important if Hibernate is to be used in a distributed environment,
Also if the second level cache implementation serializes an object it will need POJOs to be serializable
Second-level cache always associates with the Session Factory object. While running the transactions, in between it loads the objects at the Session Factory level, so that those objects will available to the entire application, don't bounds to single user. Since the objects are already loaded in the cache, whenever an object is returned by the query, at that time no need to go for a database transaction. In this way the second level cache works. Here we can use query level cache also.
Hibernate does not require that the object be serializable. In practice; however, most people do make their POJO's serializable for the following reasons:
It allows the object to be passed to an EJB.
It allows the object to be stored in a servlet session.
It may be required for some implementations of clustering and/or caching.