6 Replies Latest reply on Jul 11, 2005 2:45 PM by Jens Elkner

    Duplicate Column Error

    kee yes Newbie

      Hi All

      I have two tables with One To Many relationship

      Table A has Column B as FK where Column B is PK of Table B.

      Since I have One to Many relationship, I don't have any getter and setter for Column B inside Table A Entity. Column B is automatically generated by the OneToMany relationship. If I explicitly put a getter and setter for Colum B, it says * duplicate column * during deployment.

      But I need a setter inside Table A entity for Column B. Is it okey if I just put a setter without a getter inside Table A entity?

      If the above way is the only solution, how can I have a getter for Column B inside Table A entity?


      Regards
      K.Suresh

        • 1. Re: Duplicate Column Error
          Emmanuel Bernard Master

          I don't get you, pealse show a simple code describing your needs.

          • 2. Re: Duplicate Column Error
            kee yes Newbie

            Here it goes

            @Entity
            @Table(name = "CPAY")
            @NamedQuery(name="Cpay.findByPrimaryKey",queryString="SELECT OBJECT(c) FROM Cpay c WHERE c.cpayId =: cpayId")
            @NamedQueries({
            @NamedQuery(name = "Cpay.findByAccId",queryString="SELECT OBJECT(c) FROM Cpay c WHERE c.accountId =: accountId")
            }
            )

            public class Cpay implements java.io.Serializable
            {

            private java.lang.Long cpayId ;
            private Account account;

            @Id(generate = GeneratorType.AUTO)
            @Column(name="CPAY_ID")
            public Long getCpayId()
            {
            return cpayId ;
            }

            public void setCpayId(java.lang.Long cpayId)
            {
            this.cpayId = cpayId;
            }

            /* This creates a column by name account_id in Cpay table */
            @ManyToOne
            @JoinColumn(name = "account_id")
            public Account getAccount()
            {
            return account;
            }
            public void setAccount(Account account)
            {
            this.account = account;
            }


            If I don't put setter and getter for account_id, then the Named Query c.accountId =: accountId won't work since there is no getter for
            accountId.

            But the same time, If I put a getter and setter for accountId, while deployment it complains for a duplicate column by name account_id
            since the relationship itself creates a column account_id with referential integrity

            Regards

            • 3. Re: Duplicate Column Error
              Emmanuel Bernard Master

              where c.account.accountId = :accountId

              or even better

              where c.account = :account

              • 4. Re: Duplicate Column Error
                Jens Elkner Apprentice

                 

                "epbernard" wrote:
                or even better

                where c.account = :account


                Can you give a hint, why this is better? Just for OO-POV or perf ?

                • 5. Re: Duplicate Column Error
                  Emmanuel Bernard Master

                  it is better from an abstraction POV, not significantly slower if any

                  • 6. Re: Duplicate Column Error
                    Jens Elkner Apprentice

                    Ahh, ok. Asking because I think, performance is important and thus passing an id around (i.e. from the client to the server) might give one better performance/less network traffic, than passing the complete object (account) around...