JPA -- Best way to refresh a List association?

Hi,
I need to refresh a OneToMany association.
For example, I have two entities: Header & Detail.
@Entity
@Table(name="HEADERS")
public class Header implements Serializable {
    @OneToMany(mappedBy="header")
    private List<Detail> details;
@Entity
@Table(name="DETAILS")
public class Detail implements Serializable {
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="HDR_ID", referencedColumnName="HDR_ID")
    private Header header;
}So, I fetch the Header along with all its Details.
At a later point of time, I know that some Detail rows in the database have been changed behind my back. I need to re-fetch the list of Details. What should I do?
1. I could add a cascade parameter to the @OneToMany association. I could specify:
@OneToMany(mappedBy="header", cascade={CascadeType.REFRESH})Then I could run:
entityManager.refresh(header);The trouble is that, since all the Details are already in the cache, the cached entities will be returned, not the ones fetched from the database. So, I won't refresh a thing. A query will be sent to the database indeed, but I will get the cached (i.e. stale) entities. I don't know of a way to specify something like
setHint(TopLinkQueryHints.REFRESH, HintValues.TRUE)dynamically for associations, so that the values in the cache would be replaced with the ones fetched from the database.
2. I could try to turn off the caching for the while Entity class. The trouble is that for some reason this doesn't work (see my other question here JPA -- How can I turn off the caching for an entity? Besides, even if it worked, I don't want to turn off the caching in general. I simply want to refresh the list sometimes.
Could anyone tell me what's the best way to refresh the association?
Best regards,
Bisser

Hi Chris,
First, let me thank you that you take the time to answer my questions. I really appreciate that. I wish to apologize for my late reply but I wasn't around the PC for a while.
TopLink doesn't refresh an entity based on a view. I will try to explain in more detail. I hope you'll have patience with me because this might be a bit longer even than my previous post. I will oversimplify my actual business case.
Let's assume we have two tables and a view:
create table MASTERS
  (id number(18) not null primary key,
   master_name varchar2(50));
create table DETAILS
  (id number(18) not null primary key,
   master_id number(18) not null,   -- FK to MASTER.ID
   price number(7,2));
create view DETAILS_VW as
  select id, master_id, price
  from details;Of course, in real life the view is useful and actually peforms complex aggregate calculations on the details. But at the moment I wish to keep things as simple as possible.
So, I create Entities for the tables and the view. Here are the entities for MASTERS and DETAILS_VW, only the essential stuff (w/o getters, setters, sequence info, etc.):
@Entity
@Table(name="MASTERS")
public class Master {
     @Id
     @Column(name="ID", nullable=false)
     private Long id;
     @Column(name="MASTER_NAME")
     private String masterName;
     @OneToMany(mappedBy="master", fetch=FetchType.LAZY, cascade=CascadeType.REFRESH)
     private List<DetailVw> detailsVw;
@Entity
@Table(name="DETAILS_VW")
public class DetailVw {
     @Id
     @Column(name="ID")
     private Long id;
     @ManyToOne(fetch=FetchType.LAZY)
     @JoinColumn(name="MASTER_ID", referencedColumnName="ID")
     private Master master;
     @Column(name="PRICE")
     private Double price;
}So, now we have the tables and the entities. Let's assume one master row and two detail rows exist:
MASTER:  ID=1, MASTER_NAME='Master #1'
DETAIL:  ID=1, MASTER_ID=1, PRICE=3
DETAIL:  ID=2, MASTER_ID=1, PRICE=8And now let's run the following code:
// List the initial state
Master master = em.find(Master.class, 1L);
List<DetailVw> detailsVw = master.getDetailsVw();
for (DetailVw dv : detailsVw) {
     System.out.println(dv);
// Modify a detail
EntityTransaction tx = em.getTransaction();
tx.begin();
Detail d = em.find(Detail.class, 2L);
d.setPrice(1);
tx.commit();
// Refresh
System.out.println("----------------------------------------");
em.refresh(master);
// List the state AFTER the update
detailsVw = master.getDetailsVw();
for (DetailVw dv : detailsVw) {
     System.out.println(dv);
}And here are some excerpts from the console (only the essentials):
DetailVw: id=1, price=3
DetailVw: id=2, price=8
UPDATE DETAILS SET PRICE = ? WHERE (ID = ?)
     bind => [1, 2]
SELECT ID, MASTER_NAME FROM MASTERS WHERE (ID = ?)
     bind => [1]
SELECT ID, PRICE, MASTER_ID FROM DETAILS_VW WHERE (MASTER_ID = ?)
     bind => [1]
DetailVw: id=1, price=3
DetailVw: id=2, price=8You see, the UPDATE statement changes the DETAILS row. The price was 8, but was changed to 1. I checked the database. It was indeed changed to 1.
Furthermore, due to the refresh operation, a query was run on the view. But as you can see from the console output, the results of the query were completely ignored. The price was 8, and continued to be 8 even after the refresh. I assume it was because of the cache. If I run an explicit query on DETAILS_VW with the hint:
q.setHint(TopLinkQueryHints.REFRESH, HintValues.TRUE);then I see the real updated values. But if I only refresh with em.refresh(master), then the DetailVw entities do not get refreshed, even though a query against the database is run. I have tested this both in JavaSE and in OC4J. The results are the same.
An explicit refresh on a particular DetailVw entity works, though:
DetailVw dvw = em.find(DetailVw.class, 2L);
em.refresh(dvw);
System.out.println(dvw);Then the console says:
DetailVw: id=2, price=1So, the price is indeed 1, not 8.
If you can explain that to me, I will be really thankful!
Best regards,
Bisser

Similar Messages

  • Best way to refresh page after returning from task flow?

    Hello -
    (Using jdev 11g release 1)
    What is the best way to refresh data in a page after navigating to and returning from a task flow with an isolated data control scope where that data is changed and commited to the database?
    I have 2 bounded task flows: list-records-tf and edit-record-tf
    Both use page fragments
    list-records-tf has a list.jsff fragment and a task flow call to edit-record-tf
    The list.jsff page has a table of records that a user can click on and a button which, when pressed, will pass control to the edit-record-tf call. (There are also set property listeners on the button to set values in the request that are used as parameters to edit-record-tf.)
    The edit-record-tf always begins a new transaction and does not share data controls with the calling task flow. It consists of an application module call to set up the model according to the parameters passed in (edit record X or create new record Y or...etc.), a page fragment with a form to allow users to edit the record, and 2 different task flow returns for saving/cancelling the transaction.
    Back to the question - when I change a record in the edit page, the changes do not show up on the list page until I requery the data set. What is the best way to get the list page to refresh itself automatically upon return from the edit-record-tf?
    (If I ran the edit task flow in a popup dialog I could just use the return listener on the command component that launched the popup. But I don't want to run this in a dialog.)
    Thank you for reading my question.

    What if you have the bean which has refresh method as TF param? Call that method after you save the data. or use contextual event.

  • What is the best way to make a list of addresses for envelopes or labels?  Address book, numbers or pages?

    What is the best way to make a list of addresses for envelopes and labels?  Address book, Pages or Numbers?

    I liek your idea of having multiple images in a grid. I think
    that would be the best bet as you mentioned. Having one big picture
    would be hard to distinguish the sub-areas with mouse coordinates.
    I think checking the coordinates for the mouse would be very
    tedious because I would have to check for the left boundary, the
    right, top, and bottom for each sub-area!
    What do you mean by using button components and reskinning.
    Is this simply using buttons and changing the way they look? I'm
    just trying to save time and memory, because if I had a 10 by 10
    grid, thats a hundred buttons. Wouldn't that slow down the machine
    alot? And for that matter wouldn't having a grid of 10 by 10 images
    also by the same deal?
    Thanks for the input, I'm just trying to find the most
    efficient way to do it.

  • Access-SQL Server (Client Server Configuration) Best Way To Refresh SQL Server Records ?

    We are using Access 2013 as the front end and SQL Server 2014 as the back end to a client server configuration.
    Access controls are bound to the SQL fields with the same names. When using Access to create a new record in a Form, the data are not transferred to SQL if the form is exited to display a different Form or Access is closed. If the right or left arrow navigation
    buttons at the bottom of the form are first used to display either the previous or next record, then the data in the new record are correctly transferred to SQL.
    What is the best way to refresh the new SQL record prior to the closing of the new record in the bound Access form ? We have tried Requery of the entire form and with all of the individual controls without success. We are looking for a method of refreshing
    SQL that functions in a manner similar to that of what happens with the navigation buttons.
    Thank you very much for your assistance.
    Robert Robinson
    RERThird

    Hi Stefan,
    I had added the code to set me.dirty = False in response to the On Dirty event and didn't realize that it was working properly. I had tried other several approaches and must have become confused somewhere along the line.
    I retested the program. On Dirty is working and the problem is solved.
    Thank you very much for your assistance.
    Robert Robinson
    RERThird

  • Best way to handle large list of results in recordsets?

    Hello all.
    I'm using Dreamweaver CS3, MySQL and ASP/VBScript.
    My database of users behind my website is now approaching 25,000.
    I often have to "move" items in the database from one user record to another.
    Up and until now, I've done this simply by way of a drop down menu/list that is populated with the user ID# and Name of each and every user in the database.   This previously allowed me to simply select the ID of the Customer I wanted to "Move" the record to.
    The problem, is that the system is of course now trying to load a list of almost 25,000 user ID's each time I view the relevant site page, which is now taking so long to load it's uncomfortable.
    I've seen other sites that allow you to start typing something in to a text box and it starts filtering the results that match as you type, showing a list below.
    I assume (but am happy to be advised otherwise) that this is likely to be my best way forward, but I haven't the first clue how to do it.
    Can anyone advise?
    Regards
    David.

    You're looking for a 'type ahead' control. Try searching the web, although you may have trouble finding example code for classic asp. I did find some asp.net solutions out there.

  • Best way to transfer a List Object into a view object?

    Hi Guys and Gals,
    I'm working with some 3rd party code. This code queries a 3rd party database and returns the data into a List like so:
            PlatformSessionContext context = webutils.getPlatformContext(accesstoken,accessstokensecret,realmID,dataSource);
         QBCustomerService customerService = customerService = QBServiceFactory.getService(context, QBCustomerService.class);
         List<QBCustomer> customers = customerService.findAll(context, 1, 100);What is then the best way to populate a view object with that list? I would think I would need to do a couple of things ...
    1) Map the QBCustomer's fields/getters to my ViewObject attributes somehow ...
    2) Iterate through the List and sync the QBCustomer field values to the VO rows/attributes.
    Am I on the right track? What do you think is the best way to accomplish this? I've come across populating a VO via XML here (How do I implement an HTTP Get which returns XML into a View Object? ). Should I look for this QBCustomer.class's query and XML?
    This is all a little over my head. Any help would be appreciated. Using JDev 11.1.2.2.0.
    Thanks,
    Will

    Hi,
    bets is to do it similar as in https://blogs.oracle.com/smuenchadf/resource/examples#134
    In this sample, a list of selected keys is passed to a custom method exposed on the ViewObject. In your case you need to make sure the QBCustomer class is known by the ADF BC project. Then from the custom method, you create new rows in the VO and populate the attributes with values from the QBCustomer object. The method can be dragged from the data control palette (as a parameter form) or manually create in the PageDef (method binding). The latter case requires you to reference an object holding the list of QBCustomer
    Frank

  • What would be the best way to use a list in a textarea to compare to values in a column in a database table?

    I'm trying to move a table from a MS Access database to a datasource online so I don't have to be the only one that can perform a specific task.
    Right now I regularly am having to assess change requests to determine if it impacts the servers my team supports.  Currently I copy and paste the text list into a temporary table in MS Access then hit a button to run a query comparing what was in that list to my server inventory.  Works fine but now I need to move this online so others can do this in a place where we can also keep everyone using the exact same inventory and am planning on using a ColdFusion server.
    So what I believe would be easiest is to create a form that has a textarea where I can just copy and paste what is in the change request and then hit a submit button and go to the next page where it would list all the servers that matched (with all the other info I also need).
    Almost always the info would hit the textarea with a separate row for each server with no other delimiters, etc.
    Example info in textarea:
    servername1
    servername2
    servername3
    What is the best/easiest way in the SQL code on the following page to take the values from the textarea the way they are listed and return results of any that match the server name column from that list?  What CF functions and SQL coding are needed?
    I've done something in the past where I did WHERE Server IN (#PreserveSingleQuotes(Form.ServerList)#)...
    But I had to input 'servername1', 'servername2', 'servername3' in the text box and with how often we'll be copying lists as show above from a text area or from an excel column I'd really like a way to get from the example above to the results I need without having to manipulate.  Sometimes the list I'm comparing against may be 300+ servers and adding that formatting is not desirable.
    Any help would be appreciated.

    So here is a solution I came up with
    <cfoutput>
    <cfset Servers="#StripCR(Form.ServerList)#">
    <cfset Servers2="'#Replace(Servers, "
    ", " ", "All")#'">
    <cfset Servers3="#ToString(Servers2)#">
    <cfset Servers4="#Replace(Servers3, " ", "', '", "All")#">
    </cfoutput>
    Then in the cfquery SQL I used
    WHERE Server IN (#PreserveSingleQuotes(Servers4)#)
    Right now this is working but it seems very cumbersome.  If anyone can come up with a way to simplify this please let me know.

  • BEST WAY TO REFRESH A MATERIALIZED VIEW

    Hi, I have a Materialized View that was created after two Base Tables, Table A is a Dynamic Table, this means that it have Insert's, update's and delete's, and a Table B that is a Fixed Table, this means that this table do not change over time (it's a Date's Table). The size of the Table related to the Materialized View is to big (120 millions rows) so the refresh has to be very efficient in order to not affect the Data Base performance.
    I was thinking on a Fast Refresh mode but It would not work because the log created on the B table is not usefull, the thing is that I created the two materialized view log's (Tables A and B) and when I execute the dbms_mview.refresh(list =>'MV', method => 'F')+ sentence I got the error
    cannot use rowid column from materialized view log on "Table B" ... remember that this table don't change over time ...
    I need to mantain the Materialized view up to date, but do not know how ... Please Help !!!!!

    The Materialized View name is test_sitedate2
    The Table B name is GCO01.FV_DATES .... is a Fixed Table ... do not change over time ...
    The Code of the MV is
    CREATE MATERIALIZED VIEW TEST_SITEDATE2
    REFRESH FORCE ON DEMAND
    AS
    SELECT site_id, date_stamp
    FROM gco01.fv_site, gco01.fv_dates
    where fv_dates.date_stamp >= fv_site.start_date
    and fv_dates.date_stamp >= to_date('01/03/2010', 'dd/mm/yyyy')
    and fv_dates.date_stamp < to_date('01/04/2010', 'dd/mm/yyyy');
    Each table gco01.fv_site and gco01.fv_dates have it's materiallized view log created
    The error is ....
    SQL> execute dbms_mview.refresh(list =>'test_sitedate2', method => 'F');
    begin dbms_mview.refresh(list =>'test_sitedate2', method => 'F'); end;
    ORA-12032: cannot use rowid column from materialized view log on "GCO01"."FV_DATES"
    ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2254
    ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2460
    ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2429
    ORA-06512: at line 1
    Thank's

  • Is there a way to delete mail listing associated with a Wiki page?

    There seems to be no way to delete mailed in entries to a wiki page. In other words when I e-mail to a wiki mail list such as [email protected], the resulting entry can't be deleted. Is there a way to do this?

    You can do it if you know your way around the command line. Here's a quick article on it:
    http://rick.cogley.info/blog/index.php?id=7370998667621087152

  • VBA - Best way to refresh on open (not all queries)

    I have an AO template with many queries. However, I only want a specific query to refresh on open. Using SAPExecuteCommand's refresh crashes Excel at times. Is there an ideal way to accomplish this?
    Reason I'm even doing this is to "initialize" the prompt variables, which apparently requires first refreshing the query. I do not use the prompt dialog but instead use VBA to set the prompts. Before I can set the prompts, I have to force one of the queries to refresh. Kind of a catch 22 situation. Is there anyway to SAPExecuteCommand "initialize variables"? Refreshing the query on workbook open frequently crashes AO/Excel.
    Thanks in advance...

    Hi John,
    You're using the right Analysis API call for refreshes, but the reason you're getting the errors, sometimes, is that the workbook open event doesn't guarantee that Analysis is completely loaded and/or aware of the workbook.
    Have you tried adding a Workbook_SAP_Initialize routine to your workbook? If you add this to your workbook, you can trigger a refresh more reliably. Analysis calls the routine, if it is present, after the workbook is opened, or after Analysis is loaded, while the workbook is open.
    You may find that calling your code from this callback routine means you don't have to refresh before initializing the prompts too....
    Add this code to your workbook in the ThisWorkbook module.
         Public Sub Workbook_SAP_Initialize()
           MsgBox "Analysis just initialized " & ThisWorkbook.Name
         End Sub
    You can find more info on Workbook_SAP_Initialize in the user guide....
    Andrew

  • Looking for best way to select a list of components

    I have a button that checks user input to make sure it's the right format.
    I want this button to extend a debugger type window... I was wondering if there was a class that someone could recommend to me.
    Inside the window being extended I want there to be a table with columns labeled "Error Message", "Input", "At", "ReplaceWith". The first three will be disabled text fields, but the fourth one i want to hold a textfield with a button... Any recommendations as to how to most efficiently implement a selectable row of components would be greatly appreciated. Thanks.

    i could always just fake a table via a class
    extending a JPanel with all the data in it & just
    have an array of this class & throw those into a
    bigger JPanel... if anyone knows of a better, cleaner
    way to do this, please let me know.Possibly better to use JDialog with a JTable rather than JPanel since my guess is that you want to present this information in a modal way (though I could be wrong).

  • Best way to refresh (transport) Apex installation/configuration

    Hello,
    We have a development, test and a production environment.
    In the DVLP and TEST our developers has access (apex account) to the Apex dvlp environment for developing the Apex code and testing it.
    In our production, they have no account.
    Every x days, we do a refresh: this means we restore our full prod database to our TEST or DVLP environment.
    The result: our Apex configuration (accounts, ...) in our TEST has been overwritten.
    The apexexport -istance exports only the apex program code but not our configuration
    Does anybody have a good solution for this?
    Kind regards

    Hello Erik,
    Why do you copy the PROD database over your TST and DEV every x days?
    You probably only need the data of the 'real' tables don't you? So in that case, export only that schema (or schemas) and import these in TST en DEV and the APEX Repository won't be messed up. (You also might lose some work you've done in DEV and not promoted to PROD yet...).
    Greetings,
    Roel
    http://roelhartman.blogspot.com/

  • Best way to refresh 5 million row table

    Hello,
    I have a table with 5 million rows that needs to be refreshed every 2 weeks.
    Currently I am dropping and creating the table which takes a very long time and gives a warning related to table space at the end of execution. It does create the table with the actual number of rows but I am not sure why I get the table space warning at the end.
    Any help is greatly appreciated.
    Thanks.

    Can you please post your query.
    # What is the size of temporary tablespace
    # Is you query performing any sorts ?
    Monitor the TEMP tablespace usage from below after executing your SQL query
    SELECT TABLESPACE_NAME, BYTES_USED, BYTES_FREE
    FROM V$TEMP_SPACE_HEADER;
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Refreshing Drive List

    Hi. I have several external drives. I frequently unmount them in order to allow them to spin down and rest. What is the best way to refresh the drive list in Finder so that they appear again?

    I simply want to see the drives that are physically connected to my computer. I unmoount them to let them spin down, but then when I want to use them, I'd like to be able to find them. I can of course unplug the Firewire chord and re-plug it, but I'm guessing there is a more elegant way that that...

  • 2 way to retrieve a list of embedded fonts in Flex 4 - which one is better?

    Hi all,
    I am currently aware of 2 different methods to retrieve a list of currently available embedded fonts on the local system
    var embedededFonts : Array = Font.enumerateFonts(false)
    var appSystemManager : SystemManager = FlexGlobals.topLevelApplication.owner;           
    var embeddedFonts : Array = appSystemManager.embeddedFontList();
    What is best way to retrieve a list of embedded fonts out of those two approaches?

    "better" in what way... performance? reliability?

Maybe you are looking for

  • Does iOS 8.1.1 have these features or are they not present?

    I have an iPad Air (wifi only) and iPhone 5s. I'm wondering if the following features exist in iOS 8.1.1 and maybe I've missed it? #1- Raise to speak for Siri. I know there is "Hey Siri" but in order to use that it requires you to be a wall-hugger. I

  • ITunes 10 - artwork back for all songs in list view!

    Hi Everyone, iTunes 9 had an option in list view, were you could see the album artwork for all song on the left. iTunes 10 do not have this option or you can see them only for albums in the album list view. Apple say, it is good for saving space. But

  • Infotype check and user exit

    hi All, With the help of answer from my previous post I understand that I need to implement a user exit to do a particular check on my field. Actually when a user inputs a field then i need to compare it to field from some other table. My doubt is wh

  • Viewing photos in finder

    I am using iphoto 08, how do you view your photos within the finder? All I see is a library file (package) which opens the application.

  • Passing Data Back from a WebDynpro App to a Portal App

    Hello all, We have an iView in the portal that has a link to a webdynpro application.  When the link is clicked, it opens the webdynpro app in a new window.  When a user selects data on this window and clicks a button, I want that data selected trans