0

I have a DataNucleus project and I am using JDO to reverse map a datastore to my classes. I do this very easily with:

package com.sample;

import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(table = "source")
public class Source {

    @PrimaryKey
    private String source_id;
    private Topic topic_id;
    private String url;
    private String description;

    // getters and setters

}

public class Topic {
    private String topic_id;
    private String topicName;
    private String topicDescription;

    // getters and setters

}

The topic_id is a foreign key to another table, topic, which contains an id, a topicName, and a topicDescription.

I know that it is possible, using annotations, to return topic.id, topic.topicName, and topic.topicDescription with the topic_id. I just cannot figure out how, and I find the documentation to be a bit cryptic, especially for reverse mapping.

Can anyone lend a hand and provide an example? I've tried playing around with the @ForeignKey and @Element annotations, but I haven't had any luck yet.

Thanks!

littleK
  • 19,521
  • 30
  • 128
  • 188

1 Answers1

1

If the "topic_id" is a FK to another object (which isn't posted), then the Java class should have a Topic object field in there, like any normal 1-1 (Object-Oriented) relation

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
  • Interesting, and I need not specify any annotations? – littleK Feb 12 '13 at 18:46
  • use of annotations or XML is in the users hands as to their preference. The DN docs are very clear how you define a 1-1 relation (using annotations, or XML). a field of a persistable type is defaulted to persistent (hence no explicit metadata is needed, unless wanting to set column names etc) – DataNucleus Feb 12 '13 at 19:03
  • Hm, please see my updated code above. It is returning now without any topic_id or information in Topic. Might there still be something that I am missing? Thanks... – littleK Feb 12 '13 at 21:37
  • Thats what the log is for. You use some persistence code which is secret, and so you look at the log – DataNucleus Feb 13 '13 at 08:16
  • It seems that the SELECT statements in the logs do not include the foreign key fields. – littleK Feb 15 '13 at 17:48
  • so it must be following the fetch groups that you've defined for your query (if indeed you're using a query, because you don't state it) – DataNucleus Feb 15 '13 at 17:59