on 05-04-2006 11:50 PM
Hi, it's possible to have a foreing key a part of a primary key in JDO?
The JDO checker is complaining about that. It says "Primary key field 'person' cannot declare relationship".
For example, if I have an entity 'Person' (id, name) and and entity 'Pet' (name, age). Can I have the primary key of 'Person' (id) as a foreign key in 'Pet', and can I have a compound primary key in 'Pet' with 'name' and 'id' as the compound key?
Thanks in advance.
Rafael
Hi,
read the section named identity mapping in this <a href="http://www.jdocentral.com/JDO_Commentary_AbeWhite_1.html">article</a> for an answer to your question.
regards,
Dion
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dino,
First of all, thank you very much for your answer.
I read the article, but the solution proposed isnt clear to me. The theorical solution is: You'll have to map the foreign key columns to individual simple fields in your class rather than a single related object. At runtime, you can use the values of these fields to construct an application identity instance, which you can then use to fetch the related object
I dont understand the second sentence how would I fecht the related object at runtime?
Did you try it? Could you please send me an example? I change the type of my attributes to primitive types, and I left my .jdo and .map files as if those attributes were only primary keys how would I specify the relation at runtime with the other table?
My email is gato_lopez76@yahoo.es, I would really appreciate your help.
Best regards,
Isidro
Hi Rafael,
I have just found your post. I'm trying to do something similar, so I needed that the primary key of my class would be also a foreign key to another table.
Did you finally solve the problem? Did you find a solution?
Thank you very much in advance for your answer!!
Regards,
Isidro
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.