> Is it recommended that all hibernate persistent classes implement
> equals() and hashcode()?

It is always recommende to implement equals and hashCode for any class
that you would consider putting into java collections or other mechanisms
that tries to identity and/or sort them....so yes, it is recommende for all
persistent classes (hibernate or no hibernate :)

> If so, is it possible to implement them in a
> base class?

Yes - that is possible, but the current codegenerator (and Hibernate by
design) refrain from forcing
you to have an baseclass for your persistent classes.
I've committed a patch (my so called metaattribute patch) that would allow
the codegenerator
to seamingsly (and more easily) support such constructs as common
baseclasses and other fancy stuff (which
should not be required by the "basic" codegeneration)

> I'm doing this write now with the following toString()
> method and it works pretty well:
>
>     public String toString() {
>         StringBuffer results = new StringBuffer();
>         Class clazz = getClass();
>
>         results.append(getClass().getName() + "\n");
>
>         Field[] fields = clazz.getDeclaredFields();
>
>         try {
>             AccessibleObject.setAccessible(fields, true);
>
>             for (int i = 0; i < fields.length; i++) {
>                 results.append("\t" + fields[i].getName() + "=" +
>                                fields[i].get(this) + "\n");
>             }
>         } catch (Exception e) {
>             // ignored!
>         }
>
>         return results.toString();
>     }

This is more or less what commons-lang's reflectionToString does (which is
what Gavin's patch will make the CodeGenerator do now)

But what about your hashCode ?

/max




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to