-->
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.  [ 6 posts ] 
Author Message
 Post subject: Weird exception (on Hibernate Set)
PostPosted: Tue Jun 20, 2006 12:59 pm 
Beginner
Beginner

Joined: Sun May 16, 2004 3:53 pm
Posts: 47
Location: Belo Horizonte, Brazil
Hibernate version:2.x

Hi.
I'm getting a weird exception on a getter. I'm not posting the whole stuff (it's too big), so I'm just posting the exception and the getter in which I'm getting.
If anyone has any clue about possible and usual causes of this exception (which is in a Hibernate class), please let me know.

Exception:
java.lang.NullPointerException
at net.sf.hibernate.collection.Set.iterator(Set.java:131)

When returning the following getter (the mapping is in xdoclet, I hope it's not a problem):
Code:
/**
   * @hibernate.set table="AssocGrupoDeCamposPropTipoProp" lazy="true"
   * @hibernate.collection-key column="idTipoDeProposicao"
   *   foreign-key="FK_GrCmpPropTipoProp_TipoProp"
   * @hibernate.collection-many-to-many column="idGrupoDeCamposDeProposicao"
   *  outer-join="false"
   * class="br.ufmg.dcc.synergia.sil.tram.entidade.administracao.fase.GrupoDeCamposDeProposicao"
   * outer-join="true"
   *   foreign-key="FK_GrCmpPropTipoProp_GrCmpProp"
   * @roseuid 406DC827021F
   */
  public Collection getGruposDeCamposDeProposicao()
  {
    if (gruposDeCamposDeProposicao == null)
    {
      gruposDeCamposDeProposicao = new HashSet();
    }

    return gruposDeCamposDeProposicao;
  }


I receive the exception at this line:
Code:
Iterator it = getGruposDeCamposDeProposicao().iterator();


Thank you for any help.


Top
 Profile  
 
 Post subject: Re: Weird exception (on Hibernate Set)
PostPosted: Tue Jun 20, 2006 1:08 pm 
Beginner
Beginner

Joined: Sun Jul 10, 2005 12:11 pm
Posts: 32
Location: Hertfordshire, England
I think it is worth you posting the whole debug-level log from a test case (that just queries that iterator) to this forum, then we will be able to check through the hibernate output to see if the collections are being mapped appropriately.

_________________
--
Christian Ashby
Spiralinks, Inc.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 2:09 pm 
Beginner
Beginner

Joined: Sun May 16, 2004 3:53 pm
Posts: 47
Location: Belo Horizonte, Brazil
I'm pretty much sure that problem is not with the mappings because this class has been working for a while. However, I added a new method in it, which requires a lot of entities of this type to be instantiated.
So, after a few tries, I change the lazy="true" to lazy="false", whats causes Hibernate to not lazy instantiate that collection. My surprise is that problem no longer happens and was solved.
But I'm still wondering what the exact cause of the problem is. And I must say that from a primary insight it seems to be a Hibernate bug.
Well, if anyone else has more comments... please do so.


Top
 Profile  
 
 Post subject: Re: Weird exception (on Hibernate Set)
PostPosted: Tue Jun 20, 2006 3:05 pm 
Beginner
Beginner

Joined: Sun Jul 10, 2005 12:11 pm
Posts: 32
Location: Hertfordshire, England
Quote:
Code:
   * @hibernate.collection-many-to-many column="idGrupoDeCamposDeProposicao"
   *  outer-join="false"
   * class="br.ufmg.dcc.synergia.sil.tram.entidade.administracao.fase.GrupoDeCamposDeProposicao"
   * outer-join="true"
   *   foreign-key="FK_GrCmpPropTipoProp_GrCmpProp"



I've just noticed this entry here... There are two outer-join declarations.

Can you check the generated mapping XML files; it may be confusing things as if you want to use lazy loading, you need to have outer-join="false"

Let me know if this doesn't lead you anywhere

_________________
--
Christian Ashby
Spiralinks, Inc.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 3:30 pm 
Beginner
Beginner

Joined: Sun May 16, 2004 3:53 pm
Posts: 47
Location: Belo Horizonte, Brazil
You're right! There're two declarations!
I fixed that. However, I tried with both outer-join=false and outer-join=true and still got the same error. Only with lazy instantiation set to false, it works.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 3:41 am 
Beginner
Beginner

Joined: Sun Jul 10, 2005 12:11 pm
Posts: 32
Location: Hertfordshire, England
ltcmelo wrote:
You're right! There're two declarations!
I fixed that. However, I tried with both outer-join=false and outer-join=true and still got the same error. Only with lazy instantiation set to false, it works.

Thanks.


I've just looked at how I've done many-to-many mappings in the past, and I use the following declaration (again xdoclet):

Code:
/**
* @hibernate.set table="EMPLOYEE_RATIONALES" cascade="all" lazy="true" outer-join="false"
* @hibernate.collection-key column="EMPLID"
* @hibernate.collection-many-to-many class="com.spl.comptool.hibernate.v2.Rationale" column="RATIONALE_ID"
*/
public java.util.Set getRationaleSet() {
...
}


The only difference I can see is that the method is declared as returning a Set, not a Collection, and that I don't specify foreign keys (which should be irrelevent).

I do not however, check for null sets in this method, instead I do it as an additional method in the class (for example, getRationaleSetComplete()) - It's possible that the proxying happens _after_ the running of your getter, and so the value gets reset to null.

I don't know enough about proxying, but I do know I've had issues setting values in hibernate-proxied methods before,

If this doesn't work, can you for completeness please send the relevent portion of the xdoclet-generated mapping file for this class?

_________________
--
Christian Ashby
Spiralinks, Inc.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.