caelum / vraptor-scaffold

VRaptor Scaffold extension to make it easier configuring new projects and plugins
http://vraptor.org
MIT License
55 stars 22 forks source link

Rename model.Entity class #35

Open rodolfoliviero opened 13 years ago

rodolfoliviero commented 13 years ago

The class model.Entity can be confused with javax.persistence.Entity

rodolfoliviero commented 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?

wbotelhos commented 13 years ago

I think the model.Entity or wherever is the name is good to restric the Generic type like GenericFoo and useful to reuse the code as usual.

I tried the name as AbstractEntity, but the dom4j has this classe name too.

rodolfoliviero commented 13 years ago

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?

wbotelhos commented 13 years ago

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.

rodolfoliviero commented 13 years ago

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.

wbotelhos commented 13 years ago

Cool!

I prefer the second option.

felipefontoura commented 13 years ago

I always use Entity class to add more attributes like created_at, updated_at, ....

So I prefer the second option too.