Boa tarde, pessoal.
Estou enfrentando alguns problemas ao mapear um relacionamento com @ManyToMany. Já tentei de tudo, mas não consegui encontrar uma solução.
Abaixo segue o erro, código e as tabelas:
[color=red] Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, at table: USUARIO, for columns: [org.hibernate.mapping.Column(funcoes)][/color]
Entidade Usuario:
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import org.hibernate.envers.Audited;
import br.com.ocepar.autogestaogdh.framework.IdObject;
@Entity
@Table(name="USUARIO")
@Audited
public class Usuario extends IdObject<Integer> {
private static final long serialVersionUID = 1L;
private String nomeUsuario;
private String loginUsuario;
/*@ManyToMany
@LazyCollection(LazyCollectionOption.FALSE)
@JoinTable(name="AGG_COLABORADOR_FUNCAO" , joinColumns=@JoinColumn(name="SQ_USUARIO") , inverseJoinColumns = @JoinColumn(name="SQ_FUNCAO"))
private Set<Funcao> funcoes = new HashSet<Funcao>();
*/
private List<Funcao> funcoes;
public void setLoginUsuario(String login) {
this.loginUsuario = login;
}
@Id
@Column(name="TX_LOGIN_USUARIO", nullable=false, length=20)
public String getLoginUsuario() {
return loginUsuario;
}
@Column(name="TX_NOME_USUARIO", nullable=false, length=40)
public String getNomeUsuario() {
return nomeUsuario;
}
public void setNomeUsuario(String nomeUsuario) {
this.nomeUsuario = nomeUsuario;
}
public List<Funcao> getFuncoes() {
return funcoes;
}
@ManyToMany(targetEntity=Funcao.class, cascade=CascadeType.ALL)
@JoinTable(name="AGG_COLABORADOR_FUNCAO",
joinColumns=@JoinColumn(name="ID_USUARIO"),
inverseJoinColumns=@JoinColumn(name="ID_FUNCAO"))
public void setFuncoes(List<Funcao> funcoes) {
this.funcoes = funcoes;
}
}
Entidade Funcao:
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import org.hibernate.envers.Audited;
import br.com.ocepar.autogestaogdh.framework.IdObject;
@Entity
@Table(name="AGG_FUNCAO")
@Audited
public class Funcao extends IdObject<Integer> {
private static final long serialVersionUID = 1L;
private String descricao;
private List<Usuario> usuarios;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="SQ_FUNCAO")
public Integer getId() {
return super.getId();
}
@Column(name="DS_FUNCAO", nullable=false, length=50)
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public void setUsuarios(List<Usuario> usuarios) {
this.usuarios = usuarios;
}
@ManyToMany(mappedBy="funcoes")
public List<Usuario> getUsuarios() {
return usuarios;
}
}
Tabelas envolvidas:
Trecho da tabela usuario:
CREATE TABLE [USUARIO](
[TX_LOGIN_USUARIO] [varchar](20) NOT NULL,
[TX_NOME_USUARIO] [varchar](40) NOT NULL,
CONSTRAINT [PK_USUARIO] PRIMARY KEY
);
Tabela funcao:
CREATE TABLE [AGG_FUNCAO](
[SQ_FUNCAO] [int] IDENTITY(1,1) NOT NULL,
[DS_FUNCAO] [varchar](50) NOT NULL,
PRIMARY KEY
);
Tabela associativa:
CREATE TABLE AGG_COLABORADOR_FUNCAO (
ID_USUARIO varchar(20) NOT NULL,
ID_FUNCAO int NOT NULL,
CONSTRAINT FK_ID_USUARIO FOREIGN KEY (ID_USUARIO) REFERENCES USUARIO (TX_LOGIN_USUARIO),
CONSTRAINT FK_ID_FUNCAO FOREIGN KEY (ID_FUNCAO) REFERENCES AGG_FUNCAO (SQ_FUNCAO),
CONSTRAINT PK_COLABORADOR_FUNCAO PRIMARY KEY (ID_USUARIO,ID_FUNCAO),
);
Estou mais de 1 dia tentando resolver esse problema e nada, se alguém puder ajudar eu agradeço.
Valeu.