-->
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.  [ 2 posts ] 
Author Message
 Post subject: Probleme mit @OneToMany und HashMap - mapkey = NULL
PostPosted: Fri Dec 19, 2008 5:52 am 
Newbie

Joined: Fri Dec 19, 2008 5:28 am
Posts: 2
Hibernate version:
hibernate-annotations-3.4.0.GA
hibernate-distribution-3.3.1.GA-dist
hibernate-entitymanager-3.4.0.GA



Name and version of the database you are using:
Derby 10.1


Hi,
ich habe 3 POJOs. User, Sequence und CustomSequence. CustomSequence dient mir als Mapping zwsichen User und Sequence, da ich noch ein paar spezifische Daten mit abspeichern will. In User hab ich eine HashMap

Code:
   @OneToMany(targetEntity=CustomSequenceImpl.class, fetch=FetchType.LAZY , mappedBy="user")
   private Map<Integer, ICustomSequence> sequenceList = new HashMap<Integer, ICustomSequence>();


und in CustomSequence hab ich ein Feld vom Typ User, dass gleichzeitig mit dem Feld sequence als PK dient(mit @IdClass umgesetzt)
Code:
   @Id
   @ManyToOne
   private ISequence sequence;
   @Id
   @ManyToOne
   private IUser user;


Die CustomSequence lad ich so:

Code:
   public ICustomSequence loadCustomSequence(int seqId, IUser user) {
      ISequence sequence = (ISequence)this.loadSequence(seqId);
      CustomSequencePK customSeqPk = new CustomSequencePK();
      customSeqPk.setSequence(sequence);
      customSeqPk.setUser(user);
      ICustomSequence customSequence = (ICustomSequence)this.getEntityManager().find(CustomSequenceImpl.class, customSeqPk);
      if (customSequence == null) {
         customSequence = new CustomSequenceImpl();
         customSequence.setUser(user);
//         user.addSequence(customSequence);
         customSequence.setSequence(sequence);
         this.getEntityManager().persist(customSequence);
         System.out.println("CustomSequence saved " + customSequence.getId() + ":" +user.getId());
      } else {
         System.out.println("CustomSequence fetched " + customSequence.getId() + ":" +customSequence.getUser().getId());
      }
      return customSequence;
   }


Das funktioniert auch nocht. Nur wenn ich dann in die DB schaue sehe ich dass die Spalte "MapKey" in CustomSequence bei jedem Eintrag NULL ist.
Ich kann mir das nicht erklären. Ich denke das Problem ist sehr speziell. Hab weder hier im Forum noch bei Google was gefunden.
Was mache ich falsch?

Hier noch die IdClass
Code:
public class CustomSequencePK implements Serializable{
   
   @ManyToOne(targetEntity=SequenceImpl.class)
   @JoinColumn(nullable=false)
   private ISequence sequence;
   @ManyToOne(targetEntity=UserImpl.class)
   @JoinColumn(nullable=false)
   private IUser user;

   public CustomSequencePK(){

   } 
   
    public IUser getUser() {
        return this.user;
    }

    public void setUser(IUser user) {
        this.user = user;
    }

    public ISequence getSequence() {
        return this.sequence;
    }

    public void setSequence(ISequence sequence) {
        this.sequence = sequence;
    }

    public int hashCode() {
        return (int) this.user.getId().hashCode() + this.sequence.getId();
    }

    public boolean equals(Object obj) {
        if (obj == this) return true;
        if (obj == null) return false;
        if (!(obj instanceof CustomSequencePK)) return false;
        CustomSequencePK pk = (CustomSequencePK) obj;
        return pk.sequence.getId() == this.sequence.getId() && pk.user.getId().equals(this.user.getId());
    }

}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 23, 2008 12:55 pm 
Newbie

Joined: Fri Dec 19, 2008 5:28 am
Posts: 2
weiß keiner woran das liegt? :-/

ob ich eventuell mal im englischen teil posten soll?


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