-->
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.  [ 1 post ] 
Author Message
 Post subject: @MapKey, EAGER oder FetchMode.JOIN, equals
PostPosted: Mon Jan 18, 2010 11:23 am 
Newbie

Joined: Mon Jan 18, 2010 11:09 am
Posts: 1
Hi,

mein Problem ist, wenn ich eine Map laden will und das Loading auf EAGER stelle oder FetchMode.Join benutze, funktioniert die equals Funktion nicht mehr.
Alle Werte in der equals Funktion sind NULL außer die ID.

Woran kann das liegen?

Code:
...
public class ArticleType extends AbstractEntityDefault{

...

   @OneToMany(mappedBy = "articleType")
   @MapKey(name = "attribute")
   @Column(name = "article_type_id")
   private Map<Attribute, LinkArticleTypeAttribute> linkArticleTypeAttributes = new HashMap<Attribute, LinkArticleTypeAttribute>();

...

}

...
public class LinkArticleTypeAttribute extends AbstractEntityLink
{

...

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "article_type_id", nullable = false)
   private ArticleType articleType;

   @ManyToOne()
   @Fetch(FetchMode.JOIN)
   @JoinColumn(name = "attribute_id", nullable = false)
   private Attribute attribute;

...

}

...
public class Attribute extends AbstractEntityDefault
{

...

   @OneToMany(mappedBy = "attribute")
   private Set<LinkArticleTypeAttribute> linkArticleTypeAttributes = new HashSet<LinkArticleTypeAttribute>();

   @Override
   public boolean equals(Object obj)
   {
      System.out.println(this.getClass() + ":" + obj.getClass());
      if (this == obj) return true;
      if (obj == null) return false;
      //if (getClass() != obj.getClass()) return false;
      if (!(obj instanceof Attribute)) return false;
      Attribute other = (Attribute) obj;
      System.out.println("id: " + this.getId() + ":" + other.getId());
      System.out.println("name: " + this.name + ":" + other.name);
      if (getName() == null)
      {
         if (other.getName() != null) return false;
      }
      else if (!getName().equals(other.getName())) return false;
      return true;
   }

...

   @Override
   public int hashCode()
   {
      final int prime = 31;
      int result = 1;
      result = prime * result + ((name == null) ? 0 : name.hashCode());
      return result;
   }

...

}


Das ist der relevante Code.

Das Hibernate joined ist wegen der Performance sehr wichtig für das Projekt.

MfG


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

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.