问题
@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 {
回答1:
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
- Seam-gen uses Hibernate's reverse-engineering-tool
- If a foreign key is missing in the table, Seam-gen can not suppose one table is related to another
...
So my advice is:
- Split your @ManyToMany relationship into @OneToMany - @ManyToOne relationship
- 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,
来源:https://stackoverflow.com/questions/2073199/seam-gen-doesnt-generate-entityquery-interfaces-for-manytomany-members