javajpatoplink-essentials

Regarding Toplink Fetching Policy


I'm working for a Swing Project and the technologies used are netbeans with Toplink essentials, mysql.

The Problem I'm facing is the entity object dosn't get updated after insertions take place while calling a getter collection of the foreign key property.

Ex: I have 2 tables Table1,Table2. I have sno column, id column as a primary key in Table1 & is Foreign Key in Table2. Through find method I just get the particular sno object(existed in table 1) set some values persisted to table2 & committed the transaction.

When I select the same sno object through find method & gets its collection from Table2 through the getTable2Collection() of the bean(as it is already created in bean by toplink essential) I'm unable to get the latest added record except that all other records of it are displayed. After I close the application & opening it then the new record gets reflected while calling the same sno through the above process.

I came to know that this is a kind of lazy fetching and there should be some way of fetch policy to be changed to make the entity object get updated with the changes. So Please help me in this regard.

Regards,

Chandu


Solution

  • If you just want to try eager fetching you can specify the fetch method in your annotations (if you're using annotations) and it would look something like...

    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)