-->
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: NPE in getting the One-Side of a One-To-Many relationship
PostPosted: Wed Sep 14, 2005 6:04 am 
Beginner
Beginner

Joined: Mon Sep 12, 2005 3:27 am
Posts: 48
Hello i have the problem, that i get no object retrieved for the one-side of a one-to-many relationship. Following example-structure:

Experiment.class:


Code:
private long id;

privat Set<DaoSamples> samples = new HashSet<DaoSample>();

   @Id(generate = GeneratorType.IDENTITY)
   public Long getId() {
      return id;
   }

   public void setId(Long id) {
      this.id = id;
   }

   @OneToMany(mappedBy = "experiment")
   public Set<DaoSample> getSamples() {
      return samples;
   }

   public void setSamples(Set<DaoSamples> samples) {
      this.samples= samples;
   }


Sample.class

Code:
        private long id;

   private DaoSample experiment;

   @Id(generate = GeneratorType.IDENTITY)
   public Long getId() {
      return id;
   }

   public void setId(Long id) {
      this.id = id;
   }


   @ManyToOne (targetEntity = DaoExperiment.class)
   public DaoExperiment getExperiment() {
      return experiment;
   }

   public void setExperiment(DaoExperiment exp) {
      this.experiment= exp;
   }



If i hava an Experiment-Instance and call

Code:
List<DaoSample> listSamples = exp.getSamples();


all is fine. I get a List of Samples for this experiment. But if i then went through all samples like this, to get the experiment for this sample again, i get only a null-pointer returned:

Code:
for (DaoSample sample:exp.getSamples()) {
DaoExperiment newExperiment = sample.getExperiment() ; // only a null-Pointer returned :-(
}



What can be the mistake ? Have i misunderstud the logic of hibernate ?


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.