-->
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: Bidirektionales ManyToMany Problem
PostPosted: Mon Dec 19, 2005 12:21 pm 
Newbie

Joined: Mon Mar 21, 2005 9:41 am
Posts: 12
Hibernate version:3.0

Ich habe ein Problem mit einer bidirektionalen ManyToMany-Assoziation:
DbProcess kennt mehrere DBUSerProfiles und umgekehrt(siehe Codeblock).
Wenn ich ein DbUserProfile profile zu einem Prozess hinzufuege, dann soll danach der Prozess in profile.getProcesses auftauchen. Der Eintrag in der Jointable stimmt aber getProcesses() ist leer.
Kennt jemand dazu eine Lösung?

Code:
DbProcess:

@ManyToMany(
           targetEntity=DbUserProfile.class,
           cascade={CascadeType.PERSIST, CascadeType.MERGE}
   )
   @JoinTable(
            table=@Table(name="process_userprofile"),
            joinColumns = { @JoinColumn( name="processId") },
            inverseJoinColumns = @JoinColumn( name="profileId")
    )
   public Set<DbUserProfile> getUserProfiles()
   {
      return userProfiles;
   }


und DbUserProfiles:

@ManyToMany(
         targetEntity=DbProcess.class,
           cascade={CascadeType.PERSIST, CascadeType.MERGE}
   )
   @JoinTable(
            table=@Table(name="process_userprofile"),
            inverseJoinColumns = { @JoinColumn( name="processId") },
            joinColumns = @JoinColumn( name="profileId")
    )
   public Set<DbProcess> getProcesses()
   {
      return processes;
   }


Der Fehler tritt hier auf:
Code:
DbUserProfile out2 = new DbUserProfile();
session.save(out2);
this.process.addUserProfile(out2);
this.session.flush();

assert(out2.getProcesses() != null); //NullPointerException !!!
      


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 5:47 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Du musst das auf beiden Seiten hinzufügen.

Gruß Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


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.