Managed bean containing helper methods related to data storage functionality. It can be obtained either by calling the
Persistence.getTools() method or like any other bean, through injection or the
PersistenceTools bean has the following methods:
getDirtyFields()– returns a collection of entity attribute names that have been changed since the last load of the instance from the DB. For new instances an empty collection is returned.
isLoaded()– determines if the specified instance attribute was loaded from the DB. The attribute may not be loaded, if it was not present in the view specified when loading the instance.
This method only works for instances in the Managed state.
getReferenceId()– returns an ID of the related entity without loading it from the DB.
Let us suppose that an
Orderinstance was loaded in the persistent context and it is necessary to get the ID value of the
Customerinstance related to this
Order. A call to the
order.getCustomer().getId()method will execute the DB query to load the
Customerinstance, which in this case is unnecessary, because the value of the Customer ID is also located in the
Ordertable as a foreign key. Whereas the execution of
will not send any additional queries to the database.
This method works only for instances in the Managed state.
PersistenceTools bean can be overridden in your application to extend the set of default helper methods. An example of working with the extended interface is shown below:
MyPersistenceTools tools = persistence.getTools(); tools.foo();