-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Extra update statements following the inserts
PostPosted: Thu Sep 15, 2005 4:09 am 
Newbie

Joined: Thu Sep 15, 2005 12:59 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.