tags:

views:

203

answers:

1

@org.jboss.seam.annotations.security.management.UserRoles exposed in the User interface returns a simple List method.

seam-gen doesn't generate EntityQuery interfaces for @ManyToMany members like the getUserRoles mentioned above.

How do we enable this, so that the resultant roles are shown in a paginated fashion.

Edit 1:

This is the declaration in User.java

@ManyToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}, fetch = FetchType.LAZY)
@JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id), inverseJoinColumns = @JoinColumn(name = "role_id"))
@UserRoles
private List<Role> userRoles = new ArrayList<Role>(0);

This is the declaration in Role.java

@Entity
@Table(name = "role", uniqueConstraints = @UniqueConstraint(columnNames = "name"))
public class Role {
+4  A: 

Hi,

As said by Pete Muir, Seam lead developer

Seam-gen does not support @ManyToMany relationship

It does not generate the User Interface when using @ManyToMany. Although Seam-gen makes your life easier, sometimes, you have to do your job manually.

Before going on

  1. Seam-gen uses Hibernate's reverse-engineering-tool
  2. If a foreign key is missing in the table, Seam-gen can not suppose one table is related to another

...

So my advice is:

  1. Split your @ManyToMany relationship into @OneToMany - @ManyToOne relationship
  2. Set up reverse-engineering configuration

The reverse-engineering configuration file that Seam-gen uses is resources/seam-gen.reveng.xml inside the generated project.

Maybe you want to see

Controlling reverse engineering

Reverse engineering support in database and drivers

Added to original answer

Seam uses Ant to generate your app. Its build.xml file is located in the <SEAM_HOME>/seam-gen/build.xml

There, you will see a target called generate-ui as follows

<target name="generate-ui"

It uses a Ant Tool called hbmtemplate. It is a Template based Engine in which can be controlled by a user provided template or class. So if you want a custom behavior, you should provide your own Freemarker template. In <SEAM_HOME>/seam-gen/view directory, you can see a lot of Template files (.flt extension)

regards,

Arthur Ronald F D Garcia
Currently, I have lots of working code which is using the ManyToMany relationship. Splitting the relationship might be the right workaround for this solution, but is there any way that I could get the existing @ManyToMany List<Role> to render in a pagination fashion. I would need a mechanism to somehow tie up this list on top of the EntityQuery framework in Seam (Note: I would like not to re-do the existing code as we have already spent some time getting this to work based on @ManyToMany relationship)
Joshua
@Joshua Thanks for your reply. Saturday i will see how can i help you get your goal.
Arthur Ronald F D Garcia
@Arthur looking forward to your response (As I mentioned earlier, we have too much code based on the existing @ManyToMany relationships)
Joshua
@Arthur I am aware of the freemarker templates shipped as part of seam-gen. I guess my real problem is since @ManyToMany is specified within the parent entity (i.e. User.java), I am unable to figure out the mechanism for generating EntityQuery based classes for ManyToMany. My understanding is that the above interface works only if you define your classes as @Entity. I am not sure if you can use a POJO abstracting the ManyToMany relationship to do the same trick.
Joshua
@Joshua 1º My understanding is that the above interface works only if you define your classes as @Entity. I think so. It would help if you post your User and Role class, Seam settings (components.xml), which sean-gem comand you are using and how do you want to show your the resultant roles (view code)
Arthur Ronald F D Garcia
@Arthur - I have added info on the declarations, as part of the question. I am using the default seam-gen commands shipped as part of the seam 2.2.0 distribution
Joshua