Package io.beanmapper.annotations
Annotation Interface BeanCollection
Determines the type of the other side in a collection. When this annotation is set, beanmapper
logic is activated on it.
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionDetermines how BeanMapper must deal with the target collection.Determines the class type of an element within the target collection.When usage is CLEAR and the target collection is being managed by, eg, Hibernate's OneToMany in combination with orphanRemoval=true, clearing the collection will trigger delete statements.It is possible to set your own preferred instantiated class.
-
Element Details
-
elementType
Class elementTypeDetermines the class type of an element within the target collection. The class type will be used by BeanMapper to pass the target class type.- Returns:
- the class type of a target element collection
- Default:
void.class
-
beanCollectionUsage
BeanCollectionUsage beanCollectionUsageDetermines how BeanMapper must deal with the target collection. The default option is to apply CLEAR, which means it will reuse the collection instance by calling clear() on it. If it does not exist, it will be created. Others options are REUSE (if the collection exists, it will not be changed upfront) or CONSTRUCT (the collection is newly constructed). Note that especially CONSTRUCT will not work with frameworks like Hibernate, since the managed collection will be removed in favor of a new, unmanaged one.- Returns:
- the way the target collection must be dealt with
- Default:
CLEAR
-
preferredCollectionClass
Class preferredCollectionClassIt is possible to set your own preferred instantiated class. BeanMapper will verify whether it conforms to the possibilities. If it does, this class will be instantiated instead of the default one provided by the collection handler- Returns:
- the class to instantiate instead of the one provided by the collection handler
- Default:
void.class
-
flushAfterClear
Trinary flushAfterClearWhen usage is CLEAR and the target collection is being managed by, eg, Hibernate's OneToMany in combination with orphanRemoval=true, clearing the collection will trigger delete statements. The problem is that these statements are executed AFTER the insert statements. If a record is constrained by unicity, this might lead to a constraint violation. One way to solve this is by asking BeanMapper to flush after the call to clear. This will force Hibernate to perform the delete before the insert statements. Note that the flush also persists any merged entity. You are advised to use this functionality in combination with Lazy to make sure BeanMapper operates within the transaction scope. If you do, the flush action can be rolled back, resulting in the original state being preserved.- Returns:
- Whether to flush the collection after clearing or not.
- Default:
ENABLED
-