2
I’m having a problem in an entity relationship @Manytomany. When I try to make a simple query in the entity that contains @Manytomany a stackoverflow occurs.
My rule is simple: My Applicationcustomer can access N Webservicevo and a Webservicevo can be accessed by N Applicationcustomer. Classes are mapped as follows:
Applicaocclusive
@Entity
@Table(schema = "loaders_sch", name = "ws_aplicacoes_clientes")
public class AplicacaoClienteVO implements Serializable {
private static final long serialVersionUID = 3401460653428856555L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "id", nullable = false)
private Long id;
@Column(name = "nome_aplicacao", nullable = false, unique = true)
private String nome;
@Column(name = "usuario", nullable = false, unique = true)
private String usuarioAcesso;
@Column(name = "descricao", nullable = true)
private String descricao;
@Column(name = "password", nullable = false)
private String password;
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.DETACH)
@JoinTable(name = "ws_app_ws", joinColumns = { @JoinColumn(name = "app_id") }, inverseJoinColumns = { @JoinColumn(name = "webservice_id") })
private Set<WebserviceVO> webservices;
@Column(name = "ativo", nullable = false)
private Boolean ativo;
@Column(name = "data_criacao", nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Calendar dataCriacao;
@Column(name = "data_atualizacao", nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Calendar dataAtualizacao;
.. getters e setters omitidos
Webservicevo
@Entity
@Table(name = "ws_webservices", schema = "loaders_sch")
public class WebserviceVO implements Serializable {
private static final long serialVersionUID = -2724837366463353708L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "id", nullable = false)
private Long id;
@Column(name = "nome", nullable = false)
private String nome;
@Column(name = "aplicacao", nullable = true)
private String aplicacao;
@Column(name = "descricao", nullable = true)
private String descricao;
@ManyToMany(mappedBy = "webservices", targetEntity = AplicacaoClienteVO.class, fetch = FetchType.EAGER, cascade = CascadeType.DETACH)
private Set<AplicacaoClienteVO> appCliente;
@Column(name = "wsdl_url", nullable = false)
private String wsdlUrl;
@Column(name = "data_criacao", nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Calendar dataCriacao;
@Column(name = "data_atualizacao", nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Calendar dataAtualizacao;
...getters e setters omitidos
The query I do that stackoverflow occurs is the simplest: select app from AplicacaoClienteVO app where app.id = :id
for example.
The generated intermediate table (generated by Hibernate itself) was thus:
create table WS_APP_WS
(
app_id NUMBER(19) not null,
webservice_id NUMBER(19) not null
)
alter table WS_APP_WS
add constraint FK_E8YDQBFHUYU2Y1KKYU9YCKARB foreign key (APP_ID)
references WS_APLICACOES_CLIENTES (ID);
alter table WS_APP_WS
add constraint FK_5E67UP74MTMPYWJQVQQENCOPN foreign key (WEBSERVICE_ID)
references WS_WEBSERVICES (ID);
My mappings are wrong?
Yes, I managed it automatically by the Eclipse generator. What you recommend?
– humungs
@Ricardogiaviti what happens is that you have a circular reference (method of one class calls the method of another infinitely), do not know your level of knowledge, but anyway: If you remove all references from
Set<WebserviceVO> webservices;
within the methodshashCode()
,toString()
andequal()
of your classAplicacaoClienteVO
should work. However, it is not the right one because, until you compare your objects, you may get a wrong result, sincehashCode()
andequals()
do not have all properties defined.– Josh
@Joshua better put that in the answer, it’s the most important part of it.
– Maniero