Please use the google group to ask questions - thanks.

by Eabin 03 Mar 15:46
[Feature req.] Automatically add empty sets instead of null

currently I use this code-snipplet throughout my code:

@ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(
            name="event_group" ,
            joinColumns =
                    @JoinColumn(name="event_id"),
            inverseJoinColumns =
                    @JoinColumn(name="usergroup_id")
    ) 
    private Set<Usergroup> groups;


    if ( groups == null ) {
      final BeanSet<Usergroup> set = new BeanSet<Usergroup>();
      set.setModifyListening(BeanCollection.ModifyListenMode.ALL);
      setGroups(set);
    }
    return groups;

to avoid nullpointer-exceptions. it would be nice if ebean could automate this process.

03 Mar 15:48
by Eabin

ops, second part should be

public Set<Usergroup> getGroups() {
    if ( groups == null ) {
      final BeanSet<Usergroup> set = new BeanSet<Usergroup>();
      set.setModifyListening(BeanCollection.ModifyListenMode.ALL);
      setGroups(set);
    }
    return groups;
  }
03 Mar 20:53
by Rob

Hmmm, yes - we could do such things with enhancement.

I had been thinking about this ... when someone else hit some confusion with ManyToMany's (and the need to listen for modifications ... and basically the need to use Ebean's BeanSet, BeanList etc).

Hmmm.

05 Mar 22:23
by Rob

Create a New Topic

Title:
Body:
 
Introduction User Guide (pdf) Install/Configure Public JavaDoc Whitepapers
General Database Specific Byte Code Deployment Annotations Features
Top Bugs Top Enhancements
woResponse