Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename model.Entity class #35

Open
rodolfoliviero opened this issue Mar 19, 2011 · 7 comments
Open

Rename model.Entity class #35

rodolfoliviero opened this issue Mar 19, 2011 · 7 comments

Comments

@rodolfoliviero
Copy link
Member

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

@rodolfoliviero
Copy link
Member Author

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
Copy link
Contributor

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
Copy link
Member Author

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
Copy link
Contributor

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
Copy link
Member Author

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
Copy link
Contributor

Cool!

I prefer the second option.

@felipefontoura
Copy link
Contributor

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

So I prefer the second option too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants