Hi everyone
I'm trying to upgrade our development architecture, to build another project using the same stack.
When I try to use the same domain objects that were made using Hibernate-annotations version BETA-3, there's the following exception.
What do I have to switch?
Thanks in advance
Rafael Mauricio Nami
Sorry for the long post
Hibernate version:
Hibernate 3.2.0 CR2
Hibernate Annotations 3.2.0 CR1
Full stack trace of any exception that occurs:
org.springframework.orm.hibernate3.HibernateSystemException: cannot simultaneously fetch multiple bags; nested exception is org.hibernate.HibernateException: cannot simultaneously fetch multiple bags
Caused by: org.hibernate.HibernateException: cannot simultaneously fetch multiple bags
at org.hibernate.loader.BasicLoader.postInstantiate(BasicLoader.java:66)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:82)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1543)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at com.lucassoftwares.dao.hibernate.pessoas.PessoaDaoHibernate$1.doInHibernate(PessoaDaoHibernate.java:38)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:361)
at org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:331)
at com.lucassoftwares.dao.hibernate.pessoas.PessoaDaoHibernate.recuperarObjetos(PessoaDaoHibernate.java:41)
at com.lucassoftwares.dao.pessoas.PessoaDaoHibernateTest.testRecuperarObjetosSemParametros(PessoaDaoHibernateTest.java:284)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Annotated POJO
Code:
/**
* Classe responsável pelos dados comuns de uma pessoa.
*
* @author LUCASoftwares
*
*/
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Pessoa extends ObjetoBase {
/**
*
*/
private static final long serialVersionUID = 3453916025590025129L;
// Atributo responsável por identificar unicamente a pessoa.
private Long id;
// Atributo responsável pelo nome da pessoa.
private String nome;
// Atributo responsável pelos telefones de uma pessoa.
private List<Telefone> telefones = new ArrayList<Telefone>();
// Atributo responsável pelos endereços de uma pessoa.
private List<Logradouro> enderecos = new ArrayList<Logradouro>();
// Atributo responsável pela data de nascimento de uma pessoa.
private Date dataNascimento;
private Date dataCadastro;
private Date dataAlteracao;
/**
* Construtor padrão
*/
public Pessoa() {
super();
}
/**
* @return Returns the dataNascimento.
*/
@Column(nullable = false)
public Date getDataNascimento() {
return dataNascimento;
}
/**
* @return Returns the enderecos.
*/
@OneToMany(targetEntity = Logradouro.class, mappedBy = "pessoa")
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public List<Logradouro> getEnderecos() {
return enderecos;
}
/**
* @return Returns the id.
*/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "cd_pessoa", length = 11)
public Long getId() {
return id;
}
/**
* @return Returns the nome.
*/
@Column(nullable = false)
public String getNome() {
return nome;
}
/**
* @return Returns the telefones.
*/
@OneToMany(targetEntity = Telefone.class, mappedBy = "pessoa")
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public List<Telefone> getTelefones() {
return telefones;
}
public void addTelefone(Telefone telefone) {
telefones.add(telefone);
}
/**
* @param dataNascimento
* The dataNascimento to set.
*/
public void setDataNascimento(Date dataNascimento) {
this.dataNascimento = dataNascimento;
}
/**
* @param enderecos
* The enderecos to set.
*/
public void setEnderecos(List<Logradouro> enderecos) {
this.enderecos = enderecos;
}
public void addEndereco(Logradouro endereco) {
this.enderecos.add(endereco);
}
/**
* @param id
* The id to set.
*/
public void setId(Long id) {
this.id = id;
}
/**
* @param nome
* The nome to set.
*/
public void setNome(String nome) {
this.nome = nome;
}
/**
* @param telefones
* The telefones to set.
*/
public void setTelefones(List<Telefone> telefones) {
this.telefones = telefones;
}
/**
* @return the dataAlteracao
*/
@Column
public Date getDataAlteracao() {
return dataAlteracao;
}
/**
* @return the dataCadastro
*/
@Column(nullable=false)
public Date getDataCadastro() {
return dataCadastro;
}
/**
* @param dataAlteracao
* the dataAlteracao to set
*/
public void setDataAlteracao(Date dataAlteracao) {
this.dataAlteracao = dataAlteracao;
}
/**
* @param dataCadastro
* the dataCadastro to set
*/
public void setDataCadastro(Date dataCadastro) {
this.dataCadastro = dataCadastro;
}
/*
* (non-Javadoc)
*
* @see org.jnovice.model.ObjetoBase#hashCode()
*/
@Override
public int hashCode() {
return (id != null ? id.hashCode() : 0)
+ (nome != null ? nome.hashCode() : 0)
+ (enderecos != null ? enderecos.hashCode() : 0)
+ (telefones != null ? telefones.hashCode() : 0)
+ (dataNascimento != null ? dataNascimento.hashCode() : 0)
+ (dataCadastro != null ? dataCadastro.hashCode() : 0)
+ (dataAlteracao != null ? dataAlteracao.hashCode() : 0);
}
/*
* (non-Javadoc)
*
* @see org.jnovice.model.ObjetoBase#equals(java.lang.Object)
*/
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof Pessoa))
return false;
Pessoa p = (Pessoa) o;
if (id != null ? !id.equals(p.getId()) : p.getId() != null)
return false;
if (nome != null ? !nome.equals(p.getNome()) : p.getNome() != null)
return false;
if (dataNascimento != null ? !dataNascimento.equals(p
.getDataNascimento()) : p.getDataNascimento() != null)
return false;
if (telefones != null ? !telefones.equals(p.getTelefones()) : p
.getTelefones() != null)
return false;
if (enderecos != null ? !enderecos.equals(p.getEnderecos()) : p
.getEnderecos() != null)
return false;
if (dataCadastro != null ? !dataCadastro.equals(p.getDataCadastro()) : p.getDataCadastro() != null)
return false;
if (dataAlteracao != null ? !dataAlteracao.equals(p.getDataAlteracao()) : p.getDataAlteracao() != null)
return false;
return true;
}
/*
* (non-Javadoc)
*
* @see org.jnovice.model.ObjetoBase#toString()
*/
@Override
public String toString() {
StringBuffer result = new StringBuffer();
result.append("PESSOA...\n");
if (id != null) {
result.append("id: ");
result.append(id);
}
result.append(" \n");
result.append("nome: ");
result.append(nome);
result.append(" \n");
result.append("dataNascimento: ");
result
.append(new SimpleDateFormat("DD/MM/yyyy")
.format(dataNascimento));
result.append(" \n");
if(dataCadastro != null) {
result.append("data de cadastro: ");
result.append(dataCadastro);
result.append(" \n");
}
result.append("data de alteração: ");
result.append(dataAlteracao);
result.append(" \n");
if (telefones != null) {
for (Telefone t : telefones) {
result.append(t.toString());
}
}
if (enderecos != null) {
for (Logradouro e : enderecos) {
result.append(e.toString());
}
}
result.append(" \n");
return result.toString();
}
}
[/code]