Hi to all,
i've a question regarding performance optimizations on big objects.
We've a model where a person can have a list of AttributeValues (both are entities, clearly). Furthermore we save a ActionItem object to be able to trace changes.
This means in summary that when i want to persist one single person there will be around 133 lines in different tables for that.
1 line for the person itself
65 AttributeValues for the person
1 ActionItem for tracing
65 AttributeValues for the ActionItem
1 PersonStructureAssociation (which is an association beetween the person and lets say the place this person works at)
Here the java code for the problem above
Code:
/**
* This method will create and persist a new person with the provided gid
* and attribute values and will also try to associate the person with the
* provided structure node if it is not null
* @param gid the gid for the person
* @param attributeValues the attribute values for the person
* @param actualAssociatedNode the node to associate the person to
* @return the person itself
*/
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public Person createAndPersistNewPerson(String gid, List<PersonAttributeValue> attributeValues, StructureNode actualAssociatedNode) {
Person person = new Person();
person.setGid(gid);
/* Attribute values is a list of nearly 65 Objects.
In person class this list has a persist cascade */
person.setAttributeValues(attributeValues);
person.prePersistOrUpdate();
em.persist(person);
/* Here we persist an ActionItem with a list of also 65 attributes */
ActionItem item = actionItemCreatorBean.createActionItem(ActionType.PERSON_ADD, String.format(PersonImporterLocal.PERSON_ADD_REMARK, gid, new Date()), new ArrayList<AttributeValue>(attributeValues), person.getGid(), null);
em.persist(item);
/*Check if new person is associated to a structure*/
if (actualAssociatedNode != null) {
PersonStructureAssociation association = new PersonStructureAssociation();
association.setPerson(person);
association.setStructureNode(actualAssociatedNode);
em.persist(association);
ActionItem anotherItem = actionItemCreatorBean.createActionItem(ActionType.PERSON_ADD_TO_STRUCTURE, String.format(PersonImporterLocal.PERSON_ADD_TO_STRUCTURE_REMARK, gid, actualAssociatedNode.getType().getName(), actualAssociatedNode.getInternalSearchKey(), new Date()), null, person.getGid(), actualAssociatedNode.getInternalSearchKey());
em.persist(anotherItem);
actualAssociatedNode.addPersonAssociation(association);
em.merge(actualAssociatedNode);
}
return person;
}
The attentive reader will notice that the AttributeValues will be persisted twice (in two different tables). This is needed. I quess it would be the most benefiting performance optimization to remove the "redundant" saving of the attributeValues but unfortunally this is not possible.
Does someone know how to increase performance for this problem? Actually a persist operation for one person will last around 75 ms.
Thx for suggestions