• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
objectForPrimaryKey & restricting qualifiers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

objectForPrimaryKey & restricting qualifiers


  • Subject: objectForPrimaryKey & restricting qualifiers
  • From: David Avendasora <email@hidden>
  • Date: Mon, 29 Mar 2010 11:47:12 -0400

Hi all,

Sometimes you just need to share things that bite you. I have been having problems with objectWithPrimaryKeyValue.

Here's what I was calling:

EOUtilities.objectWithPrimaryKeyValue(ec, ENTITY_NAME, Long.valueOf(0))

When it runs, I get:

10:48:59 MyApp[9003] DEBUG NSLog  -  evaluateExpression: <com.webobjects.jdbcadaptor.EROracleExpression: "SELECT t0.CODE, t0.DESCRIPTION FROM STATUSCODE t0 WHERE t0.CODE = ?" withBindings: 1:0(id)>
10:48:59 MyApp[9003] DEBUG NSLog  - 1 row(s) processed
10:48:59 MyApp[9003] DEBUG NSLog  -  === Commit Internal Transaction
10:48:59 MyApp[9003] WARN  NSLog  - <com.webobjects.appserver._private.WOComponentRequestHandler>: Exception occurred while handling request:
com.webobjects.eoaccess.EOUtilities$MoreThanOneException: Selected more than one item for primary key {id = 0; } in entity SamsStatusCode.

The CODE in the DB is the PK, and I've executed the SQL and it returns exactly one row, just like you'd expect and the NSLog statement above says, yet I'm getting the more than one item for PK error.

Steve Meyer came up with the answer: Just because you are getting on SQL row back, doesn't mean that it doesn't represent more than one EO.

This Entity/Table is part of a Single Table Inheritance structure, and there are two oddities about the restricting qualifiers:

1) They are on the Primary Key column. For example: "id = 0 or id = 30 or id = 31"
2) They define _ranges_ as well as individual values. For example: "id > 1799 and id < 1810"

This seems to work just fine, except when we have one Entity that has no restricting qualifier, so when you call EOUtilities.objectWithPrimaryKeyValue(ec, ENTITY_NAME, Long.valueOf(0))
you get two EOs back. Because two different Entities' restricting qualifier match "id = 0" .

Happy Monday.

Dave
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: objectForPrimaryKey & restricting qualifiers
      • From: Mike Schrag <email@hidden>
  • Prev by Date: WOWODC information
  • Next by Date: Re: objectForPrimaryKey & restricting qualifiers
  • Previous by thread: WOWODC information
  • Next by thread: Re: objectForPrimaryKey & restricting qualifiers
  • Index(es):
    • Date
    • Thread