query caching is a concept,where second level caching is a part of it
If you use query caching you should also use second level caching. Failure to do so will actually result in
more queries being executed than not using query caching at all. You can use second level caching without query caching enabled however.
Second level caching is kind of a storage where query cached data are stored (not complete result set).
No. Second level cache is independent of query cache and is typically controlled by the developer (this can be tuned with hibernates cache concurrency strategy). The typical strategy is that entities are not cached in the second level cache unless explicitly marked as cacheable. This is important because you will want to make sure any entities that are returned as a result on cached query are marked cacheable, otherwise when you execute a cached query and it goes looking for entity state in the second level cache it wont find anything. If entity is marked as cacheable then all of its state is cached not just part of it.
The query cache (totally separate cache now) will store the identifiers, bound parameters, SQL statements, and scalar results (no entities just identifiers) the rest of the entity state is thrown away (this is why having a second level cache is important). The next time the query is executed if the query is found in the query cache it will look it up (using the cached identifiers) in the second level cache and Persistence Context.
"It is their responsibility to store the actual state of the entities ". does it mean the latest value from the DB is cached?
By 'their' I actually meant it is the responsibility of the second level cache to store the actual state of the entities. And it is the developers responsibility to make sure that the entity is marked as cacheable so that it cached
Does it mean the latest value from the DB is cached?
The latest value that was retrieved is cached. That does not guarantee that the data is not stale for example when something goes around the persistence context (like another application updating the database for example). Hibernate puts a lot of tools out there to avoid stale data. Some of this is done automatically and some of it is your job to configure, they can't possible be aware of every scenario that is applicable in each circumstance.
And ,If you enable query caching, the query with its parameters,sometimes scalar values like max,min, row count will also be stored in the second level caching area.
Nope it will be stored in the query cache which is totally separate from the second level cache.