Skip to content

Commit b7a7555

Browse files
committed
add code example to javadoc of CustomEntityDirtinessStrategy
1 parent e51368c commit b7a7555

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

hibernate-core/src/main/java/org/hibernate/CustomEntityDirtinessStrategy.java

+34
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,40 @@
1515
* since, by default, Hibernate must check each of the entity's attribute values one by one. Sometimes, an
1616
* application already has knowledge of an entity's dirtiness and making use of that information would save some
1717
* work. This contract allows the application to take over the task of determining if an entity is dirty.
18+
* <p>
19+
* For example, the application program might define an interface implemented by entities which keep track of
20+
* their own modified fields:
21+
* <pre>
22+
* public interface DirtyTracker {
23+
* Set&lt;String&gt; changes();
24+
* }
25+
* </pre>
26+
* Then the following implementation of {@code CustomEntityDirtinessStrategy} would be used:
27+
* <pre>
28+
* public class DirtyTrackerDirtinessStrategy implements CustomEntityDirtinessStrategy {
29+
* &#64;Override
30+
* public boolean canDirtyCheck(Object entity, EntityPersister persister, Session session) {
31+
* return entity instanceof DirtyTracker;
32+
* }
33+
*
34+
* &#64;Override
35+
* public boolean isDirty(Object entity, EntityPersister persister, Session session) {
36+
* return !((DirtyTracker) entity).changes().isEmpty();
37+
* }
38+
*
39+
* &#64;Override
40+
* public void resetDirty(Object entity, EntityPersister persister, Session session) {
41+
* ((DirtyTracker) entity).changes().clear();
42+
* }
43+
*
44+
* &#64;Override
45+
* public void findDirty(Object entity, EntityPersister persister, Session session, DirtyCheckContext dirtyCheckContext) {
46+
* dirtyCheckContext.doDirtyChecking( attributeInformation ->
47+
* ((DirtyTracker) entity).changes().contains( attributeInformation.getName() ) );
48+
* }
49+
* }
50+
* </pre>
51+
*
1852
*
1953
* @see org.hibernate.cfg.AvailableSettings#CUSTOM_ENTITY_DIRTINESS_STRATEGY
2054
* @see org.hibernate.cfg.Configuration#setCustomEntityDirtinessStrategy(CustomEntityDirtinessStrategy)

hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public class Configuration {
164164

165165
private Map<String, SqmFunctionDescriptor> customFunctionDescriptors;
166166
private List<AuxiliaryDatabaseObject> auxiliaryDatabaseObjectList;
167-
private HashMap<Class<?>, ConverterDescriptor<?,?>> attributeConverterDescriptorsByClass;
167+
private Map<Class<?>, ConverterDescriptor<?,?>> attributeConverterDescriptorsByClass;
168168
private List<EntityNameResolver> entityNameResolvers = new ArrayList<>();
169169

170170
// used to build SF

0 commit comments

Comments
 (0)