Open rodolfoliviero opened 13 years ago
this class bugs me. I am thinking to remove this class and put id, equals and hashCode in the generated model. Someone does not agree?
I think the model.Entity or wherever is the name is good to restric the Generic type like GenericFoo
I tried the name as AbstractEntity, but the dom4j has this classe name too.
Another thing that makes me thinking remove this class is that the generated method equals has a critical bug when using hibernate.
if (getClass() != obj.getClass()) { return false; }
this code breaks when the class is a proxy. (usually when using lazy relationship on collections)
A solution to fix that is use instanceof. The fragment code is something like that
if (! (obj instance of Model)) { return false; }
But this kind of code i cant put in generic class. Do you know other way to fix that?
I always use instance of and think we should use it.
But I prefer to leave the implementation of equals and hashCode within the specialized class, because the developer will decide what makes their class equals.
I know we can override the methods and adapt them to individual needs, but it forces all class have already implemented these methods even if I don't want.
it's a good point @wbotelhos I will create some option in scaffold command to create equals or to skip it.
Ex:
vraptor scaffold product name:string --skip-equals
to skip
or
vraptor scaffold product name:string --equals
to create equals based on id on generated model.
Cool!
I prefer the second option.
I always use Entity class to add more attributes like created_at, updated_at, ....
So I prefer the second option too.
The class model.Entity can be confused with javax.persistence.Entity