Re: How to handle relationship properties?
Re: How to handle relationship properties?
- Subject: Re: How to handle relationship properties?
- From: Miguel Arroz <email@hidden>
- Date: Tue, 3 Jan 2006 22:38:43 +0000
Hi!
Here goes!
The entities: User, Account, and AccountUser.
The code:
public static AccountUser accountUserForUserAndAccount( User user,
Account account, EOEditingContext context ) {
if( user == null || account == null || context == null ) {
return null;
}
NSMutableArray args = new NSMutableArray();
//args.addObject(EOUtilities.primaryKeyForObject(context,
user).objectForKey("userID"));
args.addObject(user);
EOQualifier userQualifier =
EOQualifier.qualifierWithQualifierFormat("userID = %@", args);
args.removeAllObjects();
//args.addObject(EOUtilities.primaryKeyForObject(context,
account).objectForKey("accountID"));
args.addObject(account);
EOQualifier accountQualifier =
EOQualifier.qualifierWithQualifierFormat("accountID = %@", args);
EOAndQualifier finalQualifier = new EOAndQualifier(new
NSArray( new Object[] {userQualifier, accountQualifier}));
EOFetchSpecification fetchSpecification = new
EOFetchSpecification(AccountUser.class.getName(), finalQualifier, null);
NSArray objects = context.objectsWithFetchSpecification
(fetchSpecification);
if( objects.count() != 1 ) {
NSLog.out.appendln("accountUserForUserAndAccount - could
not obtain a single accountUser object!");
}
return (AccountUser)objects.objectAtIndex(0);
}
The exception:
Error:
com.webobjects.jdbcadaptor.JDBCAdaptorException: EvaluateExpression
failed: "); }; this = ""; }(userID), 2:{values = {accountUsers = ")
>"; survey = ")>"; name = "Miguel's Account"; }; this = ""; }
(accountID)>: Next exception:SQL State:22023 -- error code: 0 -- msg:
No value specified for parameter 1.
Reason:
EvaluateExpression failed:
<com.webobjects.jdbcadaptor.PostgresqlExpression: "SELECT
t0.account_id, t0.user_id, t0.user_type FROM account_user t0 WHERE
(t0.user_id = ?::int8 AND t0.account_id = ?::int8)" withBindings: 1:
{values = {lastName = "Arroz"; status = 1; firstName = "Miguel";
email = "email@hidden"; registrationDate = 2006-01-02 14:13:08
Etc/GMT; language = "English"; timezone = "GMT"; password =
"FQrObUivnL2YCbNY+6pieSV7Co8="; activationKey = "8b76da91-
c0a8-02c9-00a4-835a0b87b8c5"; accountUsers = ("<AccountUser 83a95d
_EOVectorKeyGlobalID[AccountUser (java.lang.Integer)3,
(java.lang.Integer)2]>"); }; this = "<User d3cae0
_EOIntegralKeyGlobalID[User (java.lang.Integer)2]>"; }(userID), 2:
{values = {accountUsers =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray d227f
(<EOAccessArrayFaultHandler accountUsers _EOIntegralKeyGlobalID
[Account (java.lang.Integer)3]>)>"; survey =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray 3ecbfc
(<EOAccessArrayFaultHandler survey _EOIntegralKeyGlobalID[Account
(java.lang.Integer)3]>)>"; name = "Miguel's Account"; }; this =
"<Account 8ad183 _EOIntegralKeyGlobalID[Account (java.lang.Integer)3]
>"; }(accountID)>: Next exception:SQL State:22023 -- error code: 0
-- msg: No value specified for parameter 1.
If i uncomment the commented lines and comment the ones below
them, it works fine, but the code is ugly (well, it's not pretty!).
Could it be related to the int8 type I'm using? From what I read
on the Net, I guess this is the best value for a primary key,
specially on tables that may contain a lot of lines...
Yours
Miguel Arroz
On 2006/01/03, at 22:13, Chuck Hill wrote:
Can you post the code, the SQL, and the entire exception?
On Jan 3, 2006, at 2:06 PM, Miguel Arroz wrote:
Hi!
Maybe... I started the WO journey on 5.3 (using 5.3.1 now), so I
can't try it on 5.2! :)
Yours
Miguel Arroz
On 2006/01/03, at 18:48, Arturo Perez wrote:
Maybe it's a regression with your version of WebObjects/EOF? I'm
still on something like 5.2.4 (whatever the latest that runs
under Panther).
-arturo
Miguel Arroz wrote:
Hi!
Didn't know the tool, but downloaded and tried. Nice! :)
It works fine with my model. Of course, I cannot try my fetch
specification there because I would need the real Java object :)
but it works, I can browse, and from my AccountUser (I'm
connecting Users with Accounts), I may see a User and it's
fields, and an Account and it's fields.
Yours
Miguel Arroz
On 2006/01/03, at 13:51, Arturo Perez wrote:
I use the pgSQL and wonder plugin and I don't have this
problem. Here's something to try, and a handy thing in any case.
Are you aware of the tool called DBEdit? It's like TOAD or any
other database browser but it uses your EOModel to
intelligently navigate your schema. Can you browse through
your database successfully with DBEdit?
-arturo
Miguel Arroz wrote:
Hi!
Yes, they have the key and not the diamond.
I'm using PosgreSQL and the wonder PostgreSQL plugin. Could
that be the problem?
Yours
Miguel Arroz
On 2006/01/03, at 13:35, Arturo Perez wrote:
Miguel Arroz wrote:
Hi!
It does not work... it actually generates the correct SQL
call, with the user_id column name and such, but apparently
it can't get the primary key value from the object and
throws an exception (No value specified for parameter 1.).
Maybe if I make the primary key a class property, but that
sucks... am I doing something wrong?
"GUERRA E' PAZ
LIBERDADE E' ESCRAVIDAO
IGNORANCIA E' FORCA" -- 1984
Miguel Arroz
http://www.ipragma.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40global-village.net
This email sent to email@hidden
--
Coming in 2006 - an introduction to web applications using
WebObjects and Xcode http://www.global-village.net/wointro
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems. http://www.global-village.net/products/
practical_webobjects
"The world lies in the hands of evil
And we pray it would last" -- Apocalyptica, Life Burns!
Miguel Arroz
http://www.ipragma.com
_______________________________________________
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