On 9/17/07, adriel manalansan <[EMAIL PROTECTED]> wrote:
> Hello everybody,
>
> I think this is a stupid question but I really cant make it work. I am
> using appfuse 1.9.4 and webwork. In appfuse, it is default that
> BaseObject class implements java.io.Serializable. I have a superclass
> named BaseModel:
>
> public abstract class BaseModel extends BaseObject implements
> Serializable {
>
>     private Long id;
>
>
>     public Long getId() {
>         return id;
>     }
>
>     public void setId(Long id) {
>         this.id = id;
>     }
>
> }
>
>
> and I have a Study object:
>
> public class Study extends BaseModel implements Comparable<Study> {
>      private static final long serialVersionUID = 12345L;
>
>
>     private String name;
>     private Set<StudyPageSet> studyPageSets = new TreeSet();
>     private Set<StudyPage> studyPages = new TreeSet();
>
>     public Study() {}
>
>     public Study( String name ){
>         this.setName(name);
>     }
>
>
>     public Set<StudyPageSet> getStudyPageSets() {
>         return studyPageSets;
>     }
>
>     public void setStudyPageSets(Set<StudyPageSet> studyPageSets) {
>         this.studyPageSets = studyPageSets;
>     }
>
>     public void addStudyPageSets( StudyPageSet studyPageSet ){
>         studyPageSet.setParentStudyHead(this);
>         this.studyPageSets.add(studyPageSet);
>     }
>
>     public void removeStudyPageSet( StudyPageSet studyPageSet ){
>         studyPageSet.setParentStudyHead(null);
>         this.studyPageSets.remove(studyPageSet);
>     }
>
>     public int compareTo( Study study ) {
>       if ( this.sortOrder < study.getSortOrder() )
>         return -1;
>       if ( this.sortOrder == study.getSortOrder() )
>         return 0;
>       else
>         return 1;
>     }
>
>     public boolean equals(Object o) {
>         if (!(o instanceof Study))
>             return false;
>         Study n = (Study)o;
>         return n.getName().equals(name) &&
>                n.getId().equals(this.getId());
>     }
>
>     public int hashCode() {
>         return 31*name.hashCode();
>     }
>
>     public String toString() {
>             return name;
>     }
>

I don't think there's a problem with Serializable.  You get a
NullPointerException because name is null when you invoke it's
hashCode() method.  Add a check if name is null or use
HashCodeBuilder.reflectionHashCode(this)

-- 
Ealden Esto E. Escañan
http://ealden.net

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to