Loading ...
Sorry, an error occurred while loading the content.

primary key class with null values

Expand Messages
  • arunsl22
    Hi everyone, I m using a cmp which contains a composite primary key consisting of five fields. The problem is, among the five fields, two of them are supposed
    Message 1 of 4 , Sep 30, 2004
    View Source
    • 0 Attachment
      Hi everyone,
      I'm using a cmp which contains a composite primary key consisting of
      five fields. The problem is, among the five fields, two of them are
      supposed to be null.
      My query is as below...

      select user_id, created_date, modified_date, created_by,
      modified_by, is_primary, contact_type from internal_contacts where
      subscriber_id = ? and user_id = ? and cust_system_code = ? and
      tran_id is null and invoice_no is null ";

      if I run it in sql prompt, it returns a single row.

      How do i implement it in my primary key class or findByPrimaryKey
      method?

      Regards,
      Arun.S.L
    • Rani, Durga B
      I think this shud work by having a serializable java class say xxxPK with the following attributes subscriber_id user_id cust_system_code tran_id invoice_no
      Message 2 of 4 , Oct 1, 2004
      View Source
      • 0 Attachment
        I think this shud work by having a serializable java class say xxxPK
        with the following attributes

        subscriber_id
        user_id
        cust_system_code
        tran_id
        invoice_no

        Have the tran_id and invoice_no as Integer/Long object type rather than
        int/long.

        Implements the equals and hashcode methods as ususal.

        Provide the class name in the deployment descriptor.against the <primary
        key...tag.

        In ur client code create the instance of this xxxPK object populating
        only
        the first three attributes and invoke the findByPrimarykey with the PK
        object as
        as a parameter.

        Hope it helps.

        Regards,
        Durga

        ________________________________

        From: arunsl22 [mailto:arunsl22@...]
        Sent: Friday, October 01, 2004 10:23 AM
        To: EnterpriseBeans@yahoogroups.com
        Subject: [EnterpriseBeans] primary key class with null values


        Hi everyone,
        I'm using a cmp which contains a composite primary key consisting of
        five fields. The problem is, among the five fields, two of them are
        supposed to be null.
        My query is as below...

        select user_id, created_date, modified_date, created_by,
        modified_by, is_primary, contact_type from internal_contacts where
        subscriber_id = ? and user_id = ? and cust_system_code = ? and
        tran_id is null and invoice_no is null ";

        if I run it in sql prompt, it returns a single row.

        How do i implement it in my primary key class or findByPrimaryKey
        method?

        Regards,
        Arun.S.L




        Free SCBCD Notes :
        http://www.engineer.tk/sun/java/scbcd/notes/index.html

        FREE SCBCD Forum :
        http://www.engineer.tk/forums/viewforum.php?f=5


        Group can also be accessed by http://www.EJBs.tk



        Yahoo! Groups Sponsor
        ADVERTISEMENT
        click here
        <http://us.ard.yahoo.com/SIG=129drrg86/M=294855.5468653.6549235.3001176/
        D=groups/S=1705006905:HM/EXP=1096703045/A=2376776/R=0/SIG=11ldm1jvc/*htt
        p://promotions.yahoo.com/ydomains2004/index.html>

        <http://us.adserver.yahoo.com/l?M=294855.5468653.6549235.3001176/D=group
        s/S=:HM/A=2376776/rand=754568030>

        ________________________________

        Yahoo! Groups Links


        * To visit your group on the web, go to:
        http://groups.yahoo.com/group/EnterpriseBeans/

        * To unsubscribe from this group, send an email to:
        EnterpriseBeans-unsubscribe@yahoogroups.com
        <mailto:EnterpriseBeans-unsubscribe@yahoogroups.com?subject=Unsubscribe>


        * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
        Service <http://docs.yahoo.com/info/terms/> .




        [Non-text portions of this message have been removed]
      • Saeed Amer
        Hello Arun, One of the first and formost requirement for all fields participating in a Primary Key is that none of them may contain NULL at any time (as
        Message 3 of 4 , Oct 1, 2004
        View Source
        • 0 Attachment
          Hello Arun,

          One of the first and formost requirement for all fields participating in a Primary Key is that none of them may contain NULL at any time (as opposed to Unique Key where one or more columns may contain NULL).

          I believe that you need to rethink what columns your Primary Key should consist of.
          Hope this helps.

          Amer


          arunsl22 <arunsl22@...> wrote:
          Hi everyone,
          I'm using a cmp which contains a composite primary key consisting of
          five fields. The problem is, among the five fields, two of them are
          supposed to be null.
          My query is as below...

          select user_id, created_date, modified_date, created_by,
          modified_by, is_primary, contact_type from internal_contacts where
          subscriber_id = ? and user_id = ? and cust_system_code = ? and
          tran_id is null and invoice_no is null ";

          if I run it in sql prompt, it returns a single row.

          How do i implement it in my primary key class or findByPrimaryKey
          method?

          Regards,
          Arun.S.L




          Free SCBCD Notes :
          http://www.engineer.tk/sun/java/scbcd/notes/index.html

          FREE SCBCD Forum :
          http://www.engineer.tk/forums/viewforum.php?f=5


          Group can also be accessed by http://www.EJBs.tk


          Yahoo! Groups SponsorADVERTISEMENT


          ---------------------------------
          Yahoo! Groups Links

          To visit your group on the web, go to:
          http://groups.yahoo.com/group/EnterpriseBeans/

          To unsubscribe from this group, send an email to:
          EnterpriseBeans-unsubscribe@yahoogroups.com

          Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



          ---------------------------------
          Do you Yahoo!?
          Yahoo! Mail is new and improved - Check it out!

          [Non-text portions of this message have been removed]
        • Arun SL
          Hi Amer, Sorry for not replying. I was working on bugs all these times. I tried to use 0 instead of null, but it doesnt work. I m attaching my primary key
          Message 4 of 4 , Oct 12, 2004
          View Source
          • 0 Attachment
            Hi Amer,

            Sorry for not replying.
            I was working on bugs all these times.
            I tried to use 0 instead of null, but it doesnt work.
            I'm attaching my primary key class. please go thorough it.
            Please give me some suggestions to solve this problem.

            Regards,
            Arun.S.L

            public final class InternalPK extends java.io.Serializable
            {
            public long subscriberId = -1;
            public String userId = null;
            public String custSystemCode = null;
            public String invoiceNo = null;
            public String tranId = null;

            private int mHashCode = -1;
            public InternalPK ()
            {
            }

            public InternalPK (long aSubscriberId, String aUserId, String aCustSystemCode, String aInvoiceNo, String aTranId)
            {

            this.subscriberId = aSubscriberId;
            this.userId = aUserId;
            this.custSystemCode = aCustSystemCode;
            this.invoiceNo = aInvoiceNo;

            }

            public long getSubscriberId ()
            {
            return subscriberId;
            }

            public void setSubscriberId (long aSubscriberId)
            {
            this.subscriberId = aSubscriberId;
            }

            public String getUserId ()
            {
            return userId;
            }

            public void setUserId (String aUserId)
            {
            this.userId = aUserId;
            }

            public String getCustSystemCode ()
            {
            return custSystemCode;
            }

            public void setCustSystemCode (String aCustSystemCode)
            {
            this.custSystemCode = aCustSystemCode;
            }
            public String getInvoiceNo ()
            {
            return invoiceNo;
            }

            public void setInvoiceNo (String aInvoiceNo)
            {
            this.invoiceNo = aInvoiceNo;
            }

            public String getTranId ()
            {
            return tranId;
            }

            public void setTranId (String aTrandId)
            {
            this.tranId = aTranId;
            }


            /**
            * Returns the hash code for this primary key.
            */
            public int hashCode ()
            {
            //Compute the hashcode only once
            if (mHashCode == -1)
            {
            mHashCode = ((int)(subscriberId
            ^ userId.hashCode ()
            ^ custSystemCode.hashCode ()
            ^ (invoiceNo==null?0:invoiceNo.hashCode())
            ^ (tranId==null?0:trandId.hashCode())));
            }

            return mHashCode;
            }

            /**
            * Checks if the speified object is same as this object.
            *
            * @param aObj Object to be checked for equality
            * @returns true if the object is equal to this object; false otherwise.
            */
            public boolean equals (Object aObj)
            {
            //Return immediately if the same object.
            if (aObj == this)
            {
            return true;
            }

            //Check for equality
            boolean isEqual = false;

            //TODO Make sure that the if condition is correct...

            if (aObj instanceof InternalPK)
            {
            if ((aObj.hashCode () == hashCode ()) &&
            (((InternalPK) aObj).subscriberId == (subscriberId)) &&
            (((InternalPK) aObj).userId.equals(userId)) &&
            (((InternalPK) aObj).custSystemCode.equals(custSystemCode)) &&
            (((InternalPK) aObj).invoiceNo.equals(invoiceNo)) &&
            (((InternalPK) aObj).trandId.equals(tranId)))

            {
            isEqual = true;
            }
            else
            {
            isEqual = false;
            }
            }
            else
            {
            isEqual = false;
            }
            return isEqual;
            }

            /**
            * Return the string representation of this object.
            */
            public String toString ()
            {
            String lineSeparator = System.getProperty ("line.separator");
            StringBuffer buffer = new StringBuffer ();

            buffer.append ("subscriberId = ").append (subscriberId).append (lineSeparator);
            buffer.append ("userId = ").append (userId).append (lineSeparator);
            buffer.append ("custSystemCode = ").append (custSystemCode).append (lineSeparator);
            buffer.append ("invoiceNo = ").append (invoiceNo).append (lineSeparator);
            buffer.append ("tranId = ").append (tranId).append (lineSeparator);

            return buffer.toString ();
            }
            }

            Saeed Amer <saeedamer@...> wrote:

            Hello Arun,

            One of the first and formost requirement for all fields participating in a Primary Key is that none of them may contain NULL at any time (as opposed to Unique Key where one or more columns may contain NULL).

            I believe that you need to rethink what columns your Primary Key should consist of.
            Hope this helps.

            Amer


            arunsl22 <arunsl22@...> wrote:
            Hi everyone,
            I'm using a cmp which contains a composite primary key consisting of
            five fields. The problem is, among the five fields, two of them are
            supposed to be null.
            My query is as below...

            select user_id, created_date, modified_date, created_by,
            modified_by, is_primary, contact_type from internal_contacts where
            subscriber_id = ? and user_id = ? and cust_system_code = ? and
            tran_id is null and invoice_no is null ";

            if I run it in sql prompt, it returns a single row.

            How do i implement it in my primary key class or findByPrimaryKey
            method?

            Regards,
            Arun.S.L




            Free SCBCD Notes :
            http://www.engineer.tk/sun/java/scbcd/notes/index.html

            FREE SCBCD Forum :
            http://www.engineer.tk/forums/viewforum.php?f=5


            Group can also be accessed by http://www.EJBs.tk


            Yahoo! Groups SponsorADVERTISEMENT


            ---------------------------------
            Yahoo! Groups Links

            To visit your group on the web, go to:
            http://groups.yahoo.com/group/EnterpriseBeans/

            To unsubscribe from this group, send an email to:
            EnterpriseBeans-unsubscribe@yahoogroups.com

            Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



            ---------------------------------
            Do you Yahoo!?
            Yahoo! Mail is new and improved - Check it out!

            [Non-text portions of this message have been removed]






            Free SCBCD Notes :
            http://www.engineer.tk/sun/java/scbcd/notes/index.html

            FREE SCBCD Forum :
            http://www.engineer.tk/forums/viewforum.php?f=5


            Group can also be accessed by http://www.EJBs.tk


            Yahoo! Groups SponsorADVERTISEMENT


            ---------------------------------
            Yahoo! Groups Links

            To visit your group on the web, go to:
            http://groups.yahoo.com/group/EnterpriseBeans/

            To unsubscribe from this group, send an email to:
            EnterpriseBeans-unsubscribe@yahoogroups.com

            Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



            ---------------------------------
            Do you Yahoo!?
            vote.yahoo.com - Register online to vote today!

            [Non-text portions of this message have been removed]
          Your message has been successfully submitted and would be delivered to recipients shortly.