Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.1 and Hibernate Annotation
Mapping documents:
User:
@Entity
@Table(name = "USUARIO")
@javax.persistence.SequenceGenerator(name = "SEQ_USUARIO", sequenceName = "SEQ_USUARIO")
public class User extends BaseModel {
private Integer codigo;
@Id(generate = GeneratorType.SEQUENCE, generator = "SEQ_USUARIO")
@Column(name = "CD_USUARIO")
public Integer getCodigo() {
return codigo;
}
public void setCodigo(Integer codigo) {
this.codigo = codigo;
}
private List<Group> grupos;
@ManyToMany(cascade = { CascadeType.ALL, CascadeType.MERGE }, mappedBy = "usuarios")
public List<Group> getGrupos() {
return grupos;
}
public void setGrupos(List<Group> grupos) {
this.grupos = grupos;
}
}
Group:
@Entity
@Table(name = "GRUPO")
@javax.persistence.SequenceGenerator(name = "SEQ_GRUPO", sequenceName = "SEQ_GRUPO")
public class Group extends BaseModel {
private Integer codigo;
@Id(generate = GeneratorType.SEQUENCE, generator = "SEQ_GRUPO")
@Column(name = "CD_GRUPO")
public Integer getCodigo() {
return codigo;
}
public void setCodigo(Integer codigo) {
this.codigo = codigo;
}
private DSystem sistema;
@ManyToOne
@JoinColumn(name = "CD_SISTEMA")
public DSystem getSistema() {
return sistema;
}
public void setSistema(DSystem sistema) {
this.sistema = sistema;
}
private Collection<User> usuarios;
@ManyToMany(cascade = { CascadeType.ALL, CascadeType.MERGE })
@JoinTable(table = @Table(name = "GRUPO_USUARIO"), joinColumns = { @JoinColumn(name = "CD_GRUPO") }, inverseJoinColumns = { @JoinColumn(name = "CD_USUARIO") })
public Collection<User> getUsuarios() {
return usuarios;
}
public void setUsuarios(Collection<User> usuarios) {
this.usuarios = usuarios;
}
}
System:
@Entity
@Table(name = "SISTEMA")
@javax.persistence.SequenceGenerator(name = "SEQ_SISTEMA", sequenceName = "SEQ_SISTEMA")
public class DSystem extends BaseModel {
private Integer codigo;
@Id(generate = GeneratorType.SEQUENCE, generator = "SEQ_SISTEMA")
@Column(name = "CD_SISTEMA")
public Integer getCodigo() {
return codigo;
}
public void setCodigo(Integer codigo) {
this.codigo = codigo;
}
private String nome;
@Column(name = "NM_SISTEMA")
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
private List<Group> grupos;
@OneToMany(mappedBy = "sistema")
@JoinColumn(name = "CD_SISTEMA")
public List<Group> getGrupos() {
return grupos;
}
public void setGrupos(List<Group> grupos) {
this.grupos = grupos;
}
}
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Hi everyone,
I was writing a hql query and didn't finished because i have a question about manyToMany relationship.
I have 3 entities: User, Group and System.
User have a collection of Groups and Group have a collection of Users (Here is the ManyToMany relationship), and Group have a System (ManyToOne relationship).
So, I want to write a query to retrieve all users that are in some group that is part of one System.
Does anyone know how to help me?