views:

60

answers:

0

Please tell me, what am I doing wrong.

I have this function:

public String create(){
        try {
            Iterator<Tag> it = tags.iterator();
            List<Tag> tagList = new ArrayList<Tag>();
            while(it.hasNext()){
                Tag t = it.next();
                if (projectsTags.contains(t.getName())) {
                    tagList.add(t);
                }
            }
            Iterator<Plugin> it2 = plugins.iterator();
            List<Plugin> pluginList = new ArrayList<Plugin>();
            while(it2.hasNext()){
                Plugin p = it2.next();
                if (projectsPlugins.contains(p.getName())) {
                    pluginList.add(p);
                }
            }

            project.setTags(tagList);
        project.setPlugins(pluginList);
            Iterator<GroupRole> it3 = groupRoles.iterator();
            while (it3.hasNext()){
                GroupRole gr = it3.next();
                Group g = projectService.getGroup(gr.getGroupName());
                Role r = projectService.getRole(gr.getRoleName());
                projectsGroupRoles.put(g, r); // this is a map, a private field of this bean
            }
            project.setGroupRoles(projectsGroupRoles);
            projectService.createProject(project);

        } catch (AlreadyExistsException e) {
            facesContext = (FacesContext)ServiceFinder.getInstance().findBean("facesContext");
            facesContext.addMessage("error", new FacesMessage(FacesMessage.SEVERITY_ERROR, mf.getMessage("already_exists_msg"), null));
        }
        project = new Project();
        return "showProjects";
    }

This function projectService.createProject calls this method:

public void addProject(Project project) {

        getHibernateTemplate().save(project);
        getHibernateTemplate().flush();
    }

within a DAO. The entity to be added looks like this:

@Entity
@Table(name = "project")
public class Project implements Serializable {

    @ManyToMany(targetEntity = pl.edu.agh.adam.core.projects.hibernate.Role.class)
    @JoinTable(name = "project_group_role", joinColumns = @JoinColumn(name = "role_id"))
    @MapKeyJoinColumn(name = "group_id")
    Map<Group, Role> groupRoles;

    @Transient
    public static final String REF = "Project";

    @ManyToMany(targetEntity = pl.edu.agh.adam.core.projects.hibernate.Tag.class)
    @JoinTable(name = "project_tag", joinColumns = @JoinColumn(name = "project_id"), inverseJoinColumns = @JoinColumn(name = "tag_id"))
    private List<Tag> tags;

    @ManyToMany(targetEntity = pl.edu.agh.adam.core.plugin.hibernate.Plugin.class)
    @JoinTable(name = "project_plugin",
    joinColumns = @JoinColumn(name = "project_id"), inverseJoinColumns = @JoinColumn(name = "plugin_id"))
    private List<Plugin> plugins;

    @Transient
    public static final String PROP_ID = "id";

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "project_id")
    private Long id;

    @Transient
    public static final String PROP_NAME = "name";
    @Column(name = "name", length = 60, unique = true, nullable = false)
    private String name;

    @Transient
    public static final String PROP_SHORTNAME = "shortname";

    @Column(name = "shortname", length = 25, unique = true)
    private String shortname;

    @Transient
    public static final String PROP_HOMEPAGE = "homepage";
    @Column(name = "homepage", length = 60)
    private String homepage;

@Transient
    public static final String PROP_DESCRIPTION = "description";
    @Column(name = "description", columnDefinition = "LONGTEXT")
    private String description;
}

Everything is added fine to the project_tag and project_plugin join tables, but nothing is added to the project_group_role tale. I have checked that the proper groups and roles are fetched in the create method.

Just to be thorough, the database in a nutshell:

project - project_id + other stuff
group - group_id + other stuff
role - role_id + other stuff

project_group_role: project_id, group_id, role_id