views:

218

answers:

2

is this the right way of using it? because it does not work. i have the same thing in the RoleDAO. the two tables for users and roles are generated, but the table that links userid to roleid is not.

(more info on the syntax bellow http://xdoclet.codehaus.org/HibernateTags#HibernateTags-hibernate.manytomany hibernate xdoclet tags)

/**
 * @hibernate.id generator-class="native"
 * @hibernate.generator-param name="sequence" value="seq_userid"
 * @hibernate.many-to-many column="roleID"
 *                         class="domain.company.product.service.cm.RoleDAO.java"
 */
public Integer getUserID() {
 return userID;
}

focus please on
many-to-many column="roleID" class="domain.company.product.service.cm.RoleDAO.java"

edit:

ok. now using:

private Set<RoleDAO> roles = new HashSet<RoleDAO>();

/**
 * @hibernate.many-to-many column="roleID"
 *                         class="domain.company.producut.service.cm.RoleDAO.java"
 */
public Set<RoleDAO> getRoles() {
    return roles;
}

but still not seing the table that links roles and users.

A: 

First time I see this kind of syntax... looks weird. Is the whole thing supposed to be inside the javadoc comment?

Anyway, if you use annotations, the way to do this should be:

[in class User]

@ManyToMany
@JoinTable(name="USER_ROLE",
        joinColumns=@JoinColumn(name="USER_ID", referencedColumnName="USER_ID"),
        inverseJoinColumns=@JoinColumn(name="ROLE_ID")
)
public Set<Role> getRoles() { return roles; }

[and in class Role]

@ManyToMany(mappedBy="roles")
public Set<User> getUsers() { return users; }

This is Hibernate we're talking about... I sure hope it works for you =8-)

Yuval
lol yeah thnx :) hate legacy support. and yeah that whole thing is a javadoc.
b0x0rz
tried it. still not getting (seeing) the table that links them...??
b0x0rz
A: 

here is how i finally managed to do it.

(from UserDAO)

/**
 * @hibernate.bag table="user_roles" cascade="save-update" lazy="true"
 * @hibernate.collection-key column="roleID"
 * @hibernate.collection-many-to-many 
 *                                    class="domain.company.product.service.cm.RoleDAO"
 *                                    column="roleID"
 */
public List<RoleDAO> getRoles() {
return roles;
}
b0x0rz

related questions