Results 1 to 2 of 2

Thread: problem in bidirectional one to many associations

  1. #1
    Join Date
    Jun 2008
    Posts
    6

    Default problem in bidirectional one to many associations

    Hi,

    I have a couple of many to one relationships that involve more than two classes.

    For example:

    1 Project <-> many Resource
    1 Project<-> many Partner

    Project contains the fields

    @NotNull
    private Integer id;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "project")
    private Set<Resource> resources = new HashSet<Resource>();

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "project")
    private Set<Partner> partners = new HashSet<Partner>();


    Resource contains the fields

    @NotNull
    private Integer id;

    @ManyToOne(targetEntity = Project.class)
    @JoinColumn(name = "id")
    private Project project;


    and Partner contains the fields

    @NotNull
    private Integer id;

    @ManyToOne(targetEntity = Project.class)
    @JoinColumn(name = "id")
    private Project project;



    when I run the tests, I get the following exception (root cause only, not the full stacktrace):

    ...
    Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.mycompany.myproject.domain.Partner column: id (should be mapped with insert="false" update="false")
    ...



    When I change the ManyToOne mappings as follows, tests are OK:


    @ManyToOne(targetEntity = Project.class)
    @JoinColumn(name = "id", insertable = false, updatable = false)
    private Project project;


    I think these properties are required when two child entities reference the same parent through the same ID field.

    Has this been left intentionally like this, or is it a bug?

    Thank you for your help

    Kind Regards,

    Raul

  2. #2
    Join Date
    Mar 2008
    Location
    Sydney, AU
    Posts
    974

    Default

    This seems to be more of a JPA configuration issue. I believe you need to use @ManyToMany (available with the --cardinality attribute in the Roo shell command). Maybe you can share your complete script so we can help with it.

    Cheers,
    Stefan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •