Hi all,
I happen to have an entity say "Person" which extends from "BaseAuditEntity". The BaseAuditEntity happens to have the audit fields like modifiedDate, createdDate, modifiedBy, createdBy etc as its attributes. While creating a new person object and saving it, the sql generated happens to have an insert statement, followed by an update statement. the update statements updates the values for the audit fields. this happens even if the audit fields are null (never populated after construction). Could any one suggest how i could do away with this extra update statements? it happens to hit the performance heavily.
I am using spring/hibernate.
Hibernate version: 3.0
Mapping documents:
BaseAuditEntity.java
@EmbeddableSuperclass
public abstract class BaseAuditEntity implements Auditable {
private AuditInfo auditInfo;
@Type(type = "com.apple.ist.espresso.persistance.audit.AuditInfoType")
@Columns(columns = {
@Column(name="CREATED_DATE"),
@Column(name="CREATED_BY_ID"),
@Column(name="CREATED_BY_NAME", length=64),
@Column(name="MODIFIED_DATE"),
@Column(name="MODIFIED_BY_ID"),
@Column(name="MODIFIED_BY_NAME", length=64)})
public AuditInfo getAuditInfo() {
if(auditInfo == null) auditInfo = new AuditInfo();
return auditInfo;
}
public void setAuditInfo(AuditInfo auditInfo) {
this.auditInfo = auditInfo;
}
}
Person.java
@Entity()
@javax.persistence.SequenceGenerator (name="SEQ_STORE", sequenceName="sequencename")
@org.hibernate.annotations.Entity(selectBeforeUpdate = false,
dynamicInsert = true,
dynamicUpdate = true,
optimisticLock = OptimisticLockType.VERSION )
@Table(name="person")
public class person extends BaseAdminEntity {
private String name;
@Column(name="COLUMN_VALUE")
public String getName() {
return name;
}
public void setName(String name) {
this. name = name;
}
}
DAO.java
public class HibernatePersonDAO extends HibernateDaoSupport implements PersonDAO {
public void save(Person entity) {
getHibernateTemplate().saveOrUpdate(entity);
}
public List getAll() {
return getHibernateTemplate().loadAll(Person.class);
}
public Person getById( Long id) {
Person entity = (Person) getHibernateTemplate().get(Person.class, id);
if (entity == null) {
throw new ObjectRetrievalFailureException(Pserson.class, id);
}
return entity;
}
}
Name and version of the database you are using: oracle 10g
|