10 Replies Latest reply on Apr 15, 2005 8:27 AM by epbernard

    Unidirectional OneToMany

    schoetz

      Hi I have some problem with unidirectional OneToMany associations. As mentioned in the Specification it should work if I use a simple @OneToMany

      @OneToMany
      public Collection getLineItems() {
      return lineItems;
      }

      This should create a link-table for the assosiation. I get the following message:

      @AssociationTable, mappedBy, or @JoinColumn(s) must be specified for @OneToMany

      But none of these mentioned possibilities works. Is this not yet supported or am I doing something wrong?

      Regards
      schoetz


        • 1. Re: Unidirectional OneToMany
          bill.burke

          Specify a @JoinColumn(s) and this should work. Preview 4 does not currently implement the default mapping for this unidirectional case.

          • 2. Re: Unidirectional OneToMany
            schoetz

            I already tried this. I get this error message:

            Error parsing XML: XML String(221) The content of element type "list" must match "(meta*,subselect?,cache?,synchronize*,key,index,(element|one-to-many|many-to-many|composite-element|many-to-any),loader?,sql-insert?,sql-update?,sql-delete?,sql-delete-all?,filter*)".


            The definition looks like this:
            @OneToMany
            @JoinColumn( name = "TEST")



            schoetz

            • 3. Re: Unidirectional OneToMany
              ceracm

               

              "bill.burke@jboss.com" wrote:
              Specify a @JoinColumn(s) and this should work. Preview 4 does not currently implement the default mapping for this unidirectional case.



              I am using EJB 3.0 preview 4.

              I want to map a undirectional 1-to-many relationship with a foreign key (in the child table).

              I expected to implement this using:

              class Parent {

              @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
              @JoinColumn(name="PARENT_ID",referencedColumnName="ID")
              private Collection children
              }

              In the generated schema the child table has a FK.
              However, the generated hibernate-mapping contains inverse="true".
              The children are persisted but the foreign key is never set to the parent's pk.

              Are my annotations incorrect or is this not supported?


              • 4. Re: Unidirectional OneToMany
                bill.burke

                referencedColumn is not supported yet. I don't think it will be supported in the next release either (scheduled for this week). Apologies...

                • 5. Re: Unidirectional OneToMany
                  schoetz

                  I fixed my problem now. I used java.util.List instead of java.util.Collection. Now everything works perfect with unidirectional OneToMany-Associations.

                  schoetz

                  • 6. Re: Unidirectional OneToMany
                    epbernard

                     

                    "bill.burke@jboss.com" wrote:
                    referencedColumn is not supported yet. I don't think it will be supported in the next release either (scheduled for this week). Apologies...

                    It is supported Bill :-)

                    • 7. Re: Unidirectional OneToMany
                      ceracm

                       

                      "epbernard" wrote:
                      "bill.burke@jboss.com" wrote:
                      referencedColumn is not supported yet. I don't think it will be supported in the next release either (scheduled for this week). Apologies...

                      It is supported Bill :-)


                      Please elaborate.
                      Are you saying that it will be supported in preview 5?


                      • 8. Re: Unidirectional OneToMany
                        vincent_os

                        Hello,
                        I am having difficulty with the unidirectional OneToMany relationship.

                        I have 2 perisitant objects UserDO and ReportDO. UserDO has a OneToMany relationship with ReportDO. Here is the declaration of the mapping in UserDO:

                        /**
                        * @return Returns the reports.
                        */
                        @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
                        public Collection getReports()
                        {
                        return this.reports;
                        }

                        I am using EJB3.0 preview 5.

                        I have the following errors:

                        When I persist the UserDO the entity the persistance operation works as expected, propogating the persistance operation to the collection of ReportDO entities (I verified that all the data including the join table is populated with appropriate values in the database)

                        However, when I try to retrieve the newly perisited UserDO I get back an empty collection of reportDO.

                        Is this a known bug?

                        • 9. Re: Unidirectional OneToMany
                          vincent_os

                          Please disregard my previous posting. I discovered my mistake. The OneToMany relationship works as specified.

                          • 10. Re: Unidirectional OneToMany
                            epbernard

                             

                            "ceracm" wrote:
                            "epbernard" wrote:
                            "bill.burke@jboss.com" wrote:
                            referencedColumn is not supported yet. I don't think it will be supported in the next release either (scheduled for this week). Apologies...

                            It is supported Bill :-)


                            Please elaborate.
                            Are you saying that it will be supported in preview 5?


                            Sorry I did read too quicky.
                            Your case (ie non inverse onetomany is now supported in preview 5).
                            referencedColumnName is supported if (and only if) it points to a pk column (basically the default value), sorry :-(