-->
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.  [ 12 posts ] 
Author Message
 Post subject: Need help! Update follows each select
PostPosted: Fri Aug 26, 2005 1:26 am 
Regular
Regular

Joined: Tue Nov 09, 2004 5:15 pm
Posts: 100
Hi All,

We are using Hibernate 3.1 beta 1. We are using the custom usertype for persisting audit fields. We are using the AuditInfoType, a custom usertype based solution in WIKI. Here's how my POJO looks:




Code:
@Table(name="SAP_MODULE")
Entity(/*access=AccessType.PROPERTY*/)
      
@javax.persistence.SequenceGenerator (name="SEQ_STORE", sequenceName="SAP_MODULE_SEQ")      

public class SapModule extends BaseAdminEntity {

   private Set<ProductSapModule> productSapModule = new HashSet<ProductSapModule>();
   
   @OneToMany(cascade={CascadeType.ALL}/*,  fetch=FetchType.LAZY*/, mappedBy="sapModule"/*, targetEntity=com.apple.ist.espresso.admin.model.ProductSapModule.class*/)
   //@BatchSize(size=5)
   public Set<ProductSapModule> getProductSapModule() {
       return productSapModule;
   }
   public void setProductSapModule(Set <ProductSapModule>productSapModule) {
       this.productSapModule = productSapModule;
   
   }
}
Code:
@EmbeddableSuperclass
public abstract class BaseAdminEntity extends BaseAuditEntity {
    /**
     * Business Name of the Entity
     */
    protected String name;

    /**
     * Business description of the Entity
     */
    protected String description;

    /**
     * True if this entry is active. False otherwise.
     */
    private boolean isActive;

    /**
     * Primary Key for the Entity
     */
   
    private Long id;
   
   
   
   // private Integer version;

   
    @Id(generate=GeneratorType.SEQUENCE, generator="SEQ_STORE")
    public Long getId() {
        return id;
    }

    /**
     * @param id The id to set.
     */
    public void setId(Long id) {
        this.id = id;
    }


    @Column(name="NAME", nullable=false)
    @Length(max=64) @NotNull
    public String getName() {
        return name;
    }

    /**
     * @param name The name to set.
     */
    public void setName(String name) {
        this.name = name;
    }


    @Column(name="DESCRIPTION",nullable=false)
    @Length(max=256) @NotNull
    public String getDescription() {
        return description;
    }

    /**
     * @param description The description to set.
     */
    public void setDescription(String description) {
        this.description = description;
    }


    @Column(name="IS_ACTIVE", nullable=false)
    public boolean isActive() {
        return isActive;
    }

    /**
     * @param isDeleted The isDeleted to set.
     */
    public void setActive(boolean isActive) {
        this.isActive = isActive;
    }
   
    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return this.getClass()+" : " + "name = "+this.getName() + " , description = " + this.getDescription() + " , Active = " + this.isActive();
    }


When i run the following JUnit test case,

Code:
public class SapModuleDAOTest extends DAOTestCase {
   
   //private String tableName = "SAPMODULE";
    private BaseAdminEntityDAO sapModuleDao = null;
   // private Long id=new Long("1");

    public static void main(String[] args) {
        junit.textui.TestRunner.run(SapModuleDAOTest.class);
    }
   
    public SapModuleDAOTest(String name) {
        super(name);
        sapModuleDao = (BaseAdminEntityDAO) ctx.getBean("baseAdminEntityDAO");
    }
   
    public final void testGetById() throws Exception {
       
          Long id;
          String name = "sapModule"+System.currentTimeMillis();
          String description = "sapModule desc";
           boolean active = true;
       
           //create a POJO
        SapModule sapModule = new SapModule();
        sapModule.setName(name);
        sapModule.setDescription(description);
        sapModule.setActive(active);

        //Save
        sapModuleDao.save(sapModule);
       
        //Is the Local POJO fine ?
        id=sapModule.getId(); 
          SapModule sapModule1 = (SapModule) sapModuleDao.getById(SapModule.class, id);
        Assert.assertNotNull("SapModule retrieved correctly", sapModule1);
    }
   
    public final void testGetByInvalidId() throws Exception {
        Long testID = new Long("-1998");
        SapModule sapModule = null;
        try {
            sapModule = (SapModule) sapModuleDao.getById(SapModule.class, testID);
            fail("Invalid behavior");
        } catch (ObjectRetrievalFailureException ex) {}
    }

    public final void testGetAllActive() {
       
        Collection sapModules = sapModuleDao.getAllActive(SapModule.class);
        Iterator sapModulesIterator = sapModules.iterator();
        while (sapModulesIterator.hasNext() == true) {
            SapModule sapModule = (SapModule) sapModulesIterator.next();
            Assert.assertTrue("Active verification: ", sapModule.isActive());
   
        }
       
    }


Here's how my debug output looks:

Code:
[junit] Hibernate: select sapmodule0_.id as id, sapmodule0_.CREATED_DATE as CREATED2_49_, sapmodule0_.CREATED_BY_ID as CREATED3_49_, sapmodule0_.CREATED_BY_NAME as CREATED4_49_, sapmodule0_.MODIFIED_DATE as MODIFIED5_49_, sapmodule0_.MODIFIED_BY_ID as MODIFIED6_49_, sapmodule0_.MODIFIED_BY_NAME as MODIFIED7_49_, sapmodule0_.NAME as NAME49_, sapmodule0_.IS_ACTIVE as IS9_49_, sapmodule0_.DESCRIPTION as DESCRIP10_49_ from SAP_MODULE sapmodule0_ where sapmodule0_.IS_ACTIVE=?
    [junit] Total number of sap modules: 53
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?
    [junit] Hibernate: update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?


As you can see, for each instance returned by the session.find query, i see an update statement.

The update statement does update only for the audit fields.

Here's how the BaseAuditEntity looks:

Code:
@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"/*, nullable=false*/),
                        @Column(name="CREATED_BY_ID"/*, nullable=false, scale=12*/),
                        @Column(name="CREATED_BY_NAME"/*, nullable=false*/, length=64),
                        @Column(name="MODIFIED_DATE"/*, nullable=false*/),
                        @Column(name="MODIFIED_BY_ID"/*, nullable=false, scale=12*/),
                        @Column(name="MODIFIED_BY_NAME"/*, nullable=false*/, length=64)})
    public AuditInfo getAuditInfo() {
        if(auditInfo == null) auditInfo = new AuditInfo();
        return auditInfo;
   }
   
   public void setAuditInfo(AuditInfo auditInfo) {
      this.auditInfo = auditInfo;
   }

}


I spent almost the entire day debugging the problem with no luck. Could someone please tell me why do i see these many updates?


Thanks for any input in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 1:41 am 
Regular
Regular

Joined: Sun May 08, 2005 2:48 am
Posts: 118
Location: United Kingdom
Wild shot in the dark... Whats your SQL table description and your Hibernate mapping for SAP_MODULE table ?

Specifically what is the mapping of the CREATED_DATE and MODIFIED_DATE columns ?

update SAP_MODULE set CREATED_DATE=?, CREATED_BY_ID=?, CREATED_BY_NAME=?, MODIFIED_DATE=?, MODIFIED_BY_ID=?, MODIFIED_BY_NAME=? where id=?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 1:59 am 
Regular
Regular

Joined: Tue Nov 09, 2004 5:15 pm
Posts: 100
Hi,

Here's the table description for SAP_MODULE

SQL> desc SAP_MODULE
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NOT NULL NUMBER(19)
CREATED_DATE TIMESTAMP(6)
CREATED_BY_ID NUMBER(19)
CREATED_BY_NAME VARCHAR2(64)
MODIFIED_DATE TIMESTAMP(6)
MODIFIED_BY_ID NUMBER(19)
MODIFIED_BY_NAME VARCHAR2(64)
NAME NOT NULL VARCHAR2(64)
IS_ACTIVE NOT NULL NUMBER(1)
DESCRIPTION NOT NULL VARCHAR2(256)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 2:01 am 
Regular
Regular

Joined: Tue Nov 09, 2004 5:15 pm
Posts: 100
And here's how AuditInfo class looks like:

Code:
public final class AuditInfo implements Serializable {
    private Timestamp createdDate ;
    private Timestamp modifiedDate ;
    private Long modifiedById ;
    private Long createdById ;
    private String createdByUser;
    private String modifiedByUser;
   
   // @Column(name="MODIFIED_DATE", nullable=false, updatable=false)
    public Timestamp getModifiedDate()                 { return modifiedDate;  }
   
   
    public void setModifiedDate(Timestamp modifiedDate) { this.modifiedDate = modifiedDate; }
   
    //@Column(name="CREATED_DATE", nullable=false, updatable=false)
    public Timestamp getCreatedDate()                     { return createdDate; }
    public void setCreatedDate(Timestamp createdDate)         { this.createdDate = createdDate; }


  //  @Column(name="MODIFIED_BY", nullable=false, updatable=false)
    public Long getModifiedById()                        { return modifiedById; }
    public void setModifiedById(Long updatedBy)          { this.modifiedById = modifiedById; }

   
   // @Column(name="CREATED_BY", nullable=false, updatable=false)
    public Long getCreatedById()                        { return createdById; }
    public void setCreatedById(Long createdById)          { this.createdById = createdById; }
   
    public String getCreatedByUser()                        { return createdByUser; }
    public void setCreatedByUser(String createdByUser)          { this.createdByUser = createdByUser; }
   
    public String getModifiedByUser()                        { return modifiedByUser; }
    public void setModifiedByUser(String modifiedByUser)          { this.modifiedByUser = modifiedByUser; }

}


Top
 Profile  
 
 Post subject: side effect
PostPosted: Fri Aug 26, 2005 2:07 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
I suspect that
Code:
if(auditInfo == null) auditInfo = new AuditInfo();

is guilty.

Since H does code instrumentation it senses that object has been changed and therefore tries to save updated state of object in DB.

We do not have to call saveOrUpdate explicitly, H calls the method automatically if it senses changes in the object.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 2:14 am 
Regular
Regular

Joined: Tue Nov 09, 2004 5:15 pm
Posts: 100
Thanks kgignatyev. That makes sense. But per the Auditable interface,
Code:
public interface Auditable {
    /**
     * Instances must always return a non-null instance of AuditInfo
     */
    public AuditInfo getAuditInfo();
}


getAuditInfo should always return non-null value and this is what was suggested in the WIKI

http://www.hibernate.org/48.html

I'll try out commenting this and see how it works.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 2:15 am 
Regular
Regular

Joined: Tue Nov 09, 2004 5:15 pm
Posts: 100
Just as i expected, i got null pointer exception in AuditInfoType as below:

Code:
[junit] Testcase: testGetById(com.apple.ist.espresso.admin.dao.SapModuleDAOTest):   Caused an ERROR
    [junit] null
    [junit] java.lang.NullPointerException
    [junit]     at com.apple.ist.espresso.persistance.audit.AuditInfoType.nullSafeSet(AuditInfoType.java:140)
    [junit]     at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:141)
    [junit]     at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1617)
    [junit]     at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1594)
    [junit]     at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1850)
    [junit]     at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2200)
    [junit]     at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
    [junit]     at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
    [junit]     at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
    [junit]     at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
    [junit]     at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
    [junit]     at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    [junit]     at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
    [junit]     at com.apple.ist.espresso.util.DAOTestCase.tearDown(DAOTestCase.java:209)




Could someone please tell me how do i resolve this problem?


Top
 Profile  
 
 Post subject: how about
PostPosted: Fri Aug 26, 2005 2:19 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
How about initializing field?

private AuditInfo auditInfo = new AuditInfo()

AuditInfo getAuditInfo(){
return auditInfo;
}

......

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 2:28 am 
Regular
Regular

Joined: Tue Nov 09, 2004 5:15 pm
Posts: 100
Just tried this. The NullPointerException went away as expected but i now see one update for each select.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 2:28 am 
Regular
Regular

Joined: Sun May 08, 2005 2:48 am
Posts: 118
Location: United Kingdom
Are you using "java.sql.Timestamp" import for "Timestamp" ?

TIMESTAMP(6), this yeilds: YYMMDD format on my SQL server (not SAP).

I was thinking that the Timestamp java object time has a higher precision than the SQL one. Therefore:

Java Object "2005-08-26 09:00:00.123456" might not equal "050826"

so that looks like a modification. I maybe on the wrong track but thats my 2 cents.

What is your mapping for this table ? From hibernate-cfg.xml ?



Also with the other suggestion, try doing the object creation in the constructor for BaseAuditEntity.

private AuditInfo auditInfo = new AuditInfo()

into:

public BaseAuditEntity() {
auditInfo = new AuditInfo();
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 2:53 am 
Regular
Regular

Joined: Tue Nov 09, 2004 5:15 pm
Posts: 100
I tried moving new AuditInfo() to the constructor as well. I'm getting the same problem.

I use annotations for mapping and i've already posted it in my first post. Please refer to that posting for mapping details.

I'm using java.sql.Timestamp. Please note that the word SAP in SapModule has different meaning and we are using Oracle DB.


I'm still stuck with this problem. Could someone please help?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 10:51 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Debug custom type implementation, probably there is something wrong in "isDirty" implementation.


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

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.