CHAPTER 12 Modifying objects efficiently Modifications to
CHAPTER 12 Modifying objects efficiently Modifications to objects aren t automatically detected (no dirty checking), and SQL operations aren t executed as late as possible (no write-behind). No modification of an object and no operation you call are cascaded to any associated instance. You re working with instances of a single entity class. Any modifications to a collection that is mapped as an entity association (one-to-many, many-to-many) are ignored. Only collections of value types are considered. You therefore shouldn t map entity associations with collections, but only the noninverse side with foreign keys to many-to-one; handle the relationship through one side only. Write a query to obtain data you d otherwise retrieve by iterating through a mapped collection. The StatelessSession bypasses any enabled org.hibernate.Interceptor and can t be intercepted through the event system (both features are discussed later in this chapter). You have no guaranteed scope of object identity. The same query produces two different in-memory detached instances. This can lead to data-aliasing effects if you don t carefully implement the equals() method of your persistent classes. Good use cases for a StatelessSession are rare; you may prefer it if manual batching with a regular Session becomes cumbersome. Remember that the insert(), update(), and delete() operations have naturally different semantics than the equivalent save(), update(), and delete()operations on a regular Session. (They probably should have different names, too; the StatelessSession API was added to Hibernate ad hoc, without much planning. The Hibernate developer team discussed renaming this interface in a future version of Hibernate; you may find it under a different name in the Hibernate version you re using.) So far in this chapter, we ve shown how you can store and manipulate many objects with the most efficient strategy through cascading, bulk, and batch operations. We ll now consider interception and data filtering, and how you can hook into Hibernate s processing in a transparent fashion. 12.3 Data filtering and interception Imagine that you don t want to see all the data in your database. For example, the currently logged-in application user may not have the rights to see everything. Usually, you add a condition to your queries and restrict the result dynamically. This becomes difficult if you have to handle a concern such as security or temporal data ( Show me only data from last week, for example). Even more difficult is
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.