Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

JPA question

Thread view: 
Etam - 23 Dec 2007 03:41 GMT
Hi,

assume we have:

@Entity
public class Template {
...
    @OneToOne(mappedBy="template", cascade = ALL)
    private Document document;
    public Document getDocument() {
        return document;
    }
    public void setDocument(Document document) {
        this.document = document;
    }
...
}

and

@Entity
public class Document {
...
    @OneToOne(cascade = ALL)
    private Template template;
    public Template getTemplate() {
        return template;
    }
    public void setTemplate(Template template) {
        this.template = template;
    }
...
}

Now we write the code

Document d = new Document();
Template t = new Template();
d.setTemplate(t);

Before persisting:
d.getTemplate() gives t
but
t.getDocument() gives null.

This is quite OK.

After persisting and then fetching (fd is fetched Document):
fd.getTemplate() gives t
but
fd.getTemplate().getDocument() gives null :/.

Is it a good idea to change the above method to
public void setTemplate(Template template) {
    this.template = template;
    template.setDocument(this);
}
public void setDocument(Document document) {
    this.document = document;
    document.setTemplate(this);
}

?
shortcutter@googlemail.com - 28 Dec 2007 13:57 GMT
> Hi,
>
[quoted text clipped - 62 lines]
>
> ?

Try it out - you'll see what happens.  But do not wait too long. ;-)

robert


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.