views:

27

answers:

1

I am having problems generating a app(using "seam generate" after "seam create-project") With identifying relationship like Role , User and User_has_Role. It generates the 3 one-to-many , many-to-one entities instead of 2 @manytoMany entities. I have seen a similar question here http://stackoverflow.com/questions/2073199/seam-gen-doesnt-generate-entityquery-interfaces-for-manytomany-members

In this post here, he managed to generate many to many entities http://community.jboss.org/thread/146500

Can seamgen generate many-to-many entities ?

If i use hibernate tools separately it generates the entities correctly. I used seamgen 2.2.1CR2

+2  A: 

Ok, so this is not possible to do with seam-gen as the question you are linking too.

This is how to do it manually (which is very easy).

In your User.java entity, write the following.

@UserRoles
@ManyToMany
@JoinTable(name = "UserRoles", joinColumns = @JoinColumn(name = "userId"), inverseJoinColumns = @JoinColumn(name = "roleId"))
public List<Role> getRoles() {
    return roles;
}

This should be enough to generate/map the UserRoles table for you

Shervin
@Shervin Indeed, although seam gen can make your life easier, sometimes you have to do your job manually (+1)
Arthur Ronald F D Garcia
thank you very much for the reply. I am doing a project for my school, and it's more of a showcase of Java EE (using seam).
Ovidiu Buligan
thank you very much for the reply. I am doing a project for my school, and it's more of a showcase of Java EE (using seam). I somehow find it easier in my case without the seam generated project without the @ManyToMany relations because it generates the page to edit and add/edit roles to a user (i have more cases like this(myanytomany) , about 5) ... and somehow i gain about 60% of the functionality only from seam gen. Will i have some nasty problems if i decide to go this way?
Ovidiu Buligan
I am not sure what seam-gen generates in case of UI for this type of model. However, you still use the seam generated UI, and change it a bit so it matches your model. Shouldn't be too much work. Remember to mark the answer as accepted if you feel it is answered.
Shervin
ok .thanks for your answer :)
Ovidiu Buligan