-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Cannot simultaneously fetch multiple bags
PostPosted: Sat Sep 02, 2006 9:20 pm 
Newbie

Joined: Mon Jun 20, 2005 11:07 am
Posts: 16
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]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 05, 2006 3:42 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/#entity-mapping-association-collections

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 22, 2006 5:33 pm 
Newbie

Joined: Sat Aug 12, 2006 5:16 am
Posts: 4
Does CollectionId annotation works with one-to-many relation?

other thing is what should i put into to the column parameter?
(if i define a new name it says runtime that no such a column, if i define an existing name it says that it has been already defined..so? )

Lazlo


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 7:41 am 
Newbie

Joined: Sat Apr 01, 2006 2:23 pm
Posts: 6
I had this problem with bags as well, the easy solution is ussually to just chang the Lists to Sets.
A set is not a bag and so manby sets can be queried together.
This will of course only work if a set is good enough for you and the collection never has duplicate values (which is true in most OneToMany connections).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.