HowTo: Replace values in Entity, best practice

I was reading jsr-220 and now I have a question.
What is the best practice to replace values in an entity?
For example I have an entity Person:
@Table(name = "Person", schema = SCHEMA)
public class Person{
     @Id
     @GeneratedValue
     private int id;
     private String sourceUri;
       @ManyToMany(fetch=FetchType.EAGER, cascade={CascadeType.MERGE, CascadeType.REFRESH, CascadeType.PERSIST} )
     private List<Representative> representatives;
     @OrderBy("date")
     @ManyToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL}, mappedBy="person")
        private List<PersonAccessCounter> counter;
     @OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL}, mappedBy="person")
     private List<EducationLevel> educationLevels;
      //some other fileds + getters/setters
}As you can see, my Person has autoGenerated id. But also it has other "unformal" identity field: sourceUri
Imagine such situation:
I've persisted a Person. While system was in use, it's id points to some other entities. So I can't loose it.
Then, my special crawler gathered new info about person.
Using sourceUri of Person(crawler has provided it) I can select already persisted person from DB.
Now, my task is to completely remove some fields (this data must disappear from DB, totally, no orphaned links) from persisted person and replace them with values from new person gathered by crawler.
What's better?
1. Find persitedPerson using sourceUri
2. Replace some fields of persitedPerson with new values taken from crawledPerson.
3. em.merge(persistedPerson)
OR
1. Find persitedPerson using sourceUri.
2. Set some fields of persitedPerson to NULL
3. Merge persitedPerson
4. Set new values to persitedPerson taken from crawledPerson.
3. em.merge(persistedPerson)
Seems like the first variant is enough. It will fork fine if annotations were set correctly (cascade={CascadeType.ALL} and other)
Edited by: Holod on 10.11.2008 16:32
Edited by: Holod on 10.11.2008 16:46

I was reading jsr-220 and now I have a question.
What is the best practice to replace values in an entity?
For example I have an entity Person:
@Table(name = "Person", schema = SCHEMA)
public class Person{
     @Id
     @GeneratedValue
     private int id;
     private String sourceUri;
       @ManyToMany(fetch=FetchType.EAGER, cascade={CascadeType.MERGE, CascadeType.REFRESH, CascadeType.PERSIST} )
     private List<Representative> representatives;
     @OrderBy("date")
     @ManyToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL}, mappedBy="person")
        private List<PersonAccessCounter> counter;
     @OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL}, mappedBy="person")
     private List<EducationLevel> educationLevels;
      //some other fileds + getters/setters
}As you can see, my Person has autoGenerated id. But also it has other "unformal" identity field: sourceUri
Imagine such situation:
I've persisted a Person. While system was in use, it's id points to some other entities. So I can't loose it.
Then, my special crawler gathered new info about person.
Using sourceUri of Person(crawler has provided it) I can select already persisted person from DB.
Now, my task is to completely remove some fields (this data must disappear from DB, totally, no orphaned links) from persisted person and replace them with values from new person gathered by crawler.
What's better?
1. Find persitedPerson using sourceUri
2. Replace some fields of persitedPerson with new values taken from crawledPerson.
3. em.merge(persistedPerson)
OR
1. Find persitedPerson using sourceUri.
2. Set some fields of persitedPerson to NULL
3. Merge persitedPerson
4. Set new values to persitedPerson taken from crawledPerson.
3. em.merge(persistedPerson)
Seems like the first variant is enough. It will fork fine if annotations were set correctly (cascade={CascadeType.ALL} and other)
Edited by: Holod on 10.11.2008 16:32
Edited by: Holod on 10.11.2008 16:46

Similar Messages

  • Value or binding, best practice.

    I was using a lot of value attribute before. Played with Sun Creator lately and realized that it is using binding very heavily.
    What's the best practice to use value and binding?
    To use binding, it's more like Java Swing. You can access the UI Component inside the page bean. To use value, the user input is converted to the right type by the framework, which is very convenient.
    thanks.

    Note that you can use both at the same time.
    I think that if you're comfortable with the concept of coding a "model" for your data - instead of just, say, writing JDBC calls - then the best practice is to use "value", and use "binding" only where you need to specifically access the component for component-ish things. This'll keep your model cleanly isolated from your view, generally considered a good thing.
    But if you've got a strong personal preference for just talking to APIs like JDBC directly, and don't want the extra abstraction of a model layer, then by all means use "binding". Sun's JS Creator is targetted at that sort of developer.
    Hope this helps.
    -- Adam Winer (EG member)

  • Best practice for default values in EO

    I have and entity called AUTH_USER (a user table) within it has 2 TIMESTAMP WITH TIME ZONE columns like this ...:
    EFF_DATE TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT current_timestamp,
    TERM_DATE TIMESTAMP WITH TIME ZONE
    Notice EFF_DATE has a default constraint and is not nullable.
    In the EO, EFF_DATE is represented as a TIMESTAMPTZ and is checked as MANDATORY in its attribute properties. I cannot commit a NEW RECORD based on VO derived from this EO because of the MANDATORY constraint that is set in the EFF_DATE attribute's properties unless I enter a value. My original strategy was to have the field populated by a DEFAULT DATE if the user should attempt to leave this field null.
    This is my deli ma.
    1. I could have the database populate the value based on the default constraint in the table definition. Since EFF_DATE and TERM_DATE resemble the Effective Date (Start, End) properties that the framework already provides then I could set both fields as Effective Date (Start, End) and then check Refresh After Insert. But this still won't work unless I deselect the mandatory property on EFF_DATE.
    2. The previous solution would work. However, I'm not sure that it is part of a "Best Practices" solution. In my mind if a database column is mandatory in the database then it should be mandatory in the Model as well.
    3. If the first option is a poor choice, then what I need to do is to leave the attribute defined and mandatory and have a DEFAULT VALUE set in the RowImpl create method.
    4. Finally, I could just force the user to enter a value. That would seem to be the common sense thing to do. I mean that's what calendar widgets and AJAX enabled JSF are for!
    Regardless to what the correct answer is, I'd like to see some sample code of how the date can be populated inside the RowImpl create method and it pass to setEffDate(TimestampTZ dt). Keep in mind though that in this instance I need the timezone at the database server side and not the client side. I would also ask for advice on doing this with Groovy Scripting or expressions.
    And finally, what is the best practice in this situation?
    Thanks in advance.

    How about setting the default value property of the attribute in the EO to be adf.currentDate ?
    (assuming you are using 11g).
    This way there is a default date being set when the record is created and the user can change it if he wants to.

  • Best Practice for Extracting a Single Value from Oracle Table

    I'm using Oracle Database 11g Release 11.2.0.3.0.
    I'd like to know the best practice for doing something like this in a PL/SQL block:
    DECLARE
        v_student_id    student.student_id%TYPE;
    BEGIN
        SELECT  student_id
        INTO    v_student_id
        FROM    student
        WHERE   last_name = 'Smith'
        AND     ROWNUM = 1;
    END;
    Of course, the problem here is that when there is no hit, the NO_DATA_FOUND exception is raised, which halts execution.  So what if I want to continue in spite of the exception?
    Yes, I could create a nested block with EXCEPTION section, etc., but that seems clunky for what seems to be a very simple task.
    I've also seen this handled like this:
    DECLARE
        v_student_id    student.student_id%TYPE;
        CURSOR c_student_id IS
            SELECT  student_id
            FROM    student
            WHERE   last_name = 'Smith'
            AND     ROWNUM = 1;
    BEGIN
        OPEN c_student_id;
        FETCH c_student_id INTO v_student_id;
        IF c_student_id%NOTFOUND THEN
            DBMS_OUTPUT.PUT_LINE('not found');
        ELSE
            (do stuff)
        END IF;
        CLOSE c_student_id;   
    END;
    But this still seems like killing an ant with a sledge hammer.
    What's the best way?
    Thanks for any help you can give.
    Wayne

    Do not design in order to avoid exceptions. Do not code in order to avoid exceptions.
    Exceptions are good. Damn good. As it allows you to catch an unexpected process branch, where execution did not go as planned and coded.
    Trying to avoid exceptions is just plain bloody stupid.
    As for you specific problem. When the SQL fails to find a row and a value to return, what then? This is unexpected - if you did not want a value, you would not have coded the SQL to find a value. So the SQL not finding a value is an exception to what you intend with your code. And you need to decide what to do with that exception.
    How to implement it. The #1 rule in software engineering - modularisation.
    E.g.
    create or replace function FindSomething( name varchar2 ) return foo.col1%type is
      id foo.col1%type;
    begin
      select col1 into id from foo where col2 = upper(name);
      return( id );
    exception when NOT_FOUND then
      return( null );
    end;
    And that is your problem. Modularisation. You are not considering it.
    And not the only problem mind you. Seems like your keyboard has a stuck capslock key. Writing code in all uppercase is just as bloody silly as trying to avoid exceptions.

  • What is the best practice concerning View Objects and List of values

    Hi,
    Let's take these two tables :
    Market_Descriptions
    Id
    Name
    Desc
    Language_Id
    Languages
    Id
    Code
    Desc
    Now, if I am generating these business components with the help of the wizard, I will be having two entities and two views.
    If I am creating a list of value on the field Language_Id in Market_Descriptions table, showing the language code, everything works fine as long as this is drop as a Form but not as a table or read-only form.
    What is the best practice for me to include/replace the language_id with the language code, since it is more user-friendly, on a read-only form or a table?
    Thanks.

    Hi,
    Always have LOV on the field which we want show it on UI. Suppose based on below scenario, If you want to display Langaugae Description on UI, have LOV on Desc but not on Language_Id. Even though we can set display attribute in LOV configuration, but it will work only in forms but not in tables. In tables it will show language id instead of description.
    Have LOV on Desc and make one more join with location Id in LOV configuration, so as soon as we select desc in LOV, location_id will be populated.
    here is the join condition inside LOV
    Languages.Desc = ViewAccessor.Desc
    Languages.Id - ViewAccessor.Desc
    Hope this will help you.
    Dileep.

  • What are the best practices to replace a disk in 6140 ?

    What are the best practices to replace a disk in 6140?
    Regards

    The best way is to follow CAM Service Advisor instructions.

  • BEST PRACTICE FOR THE REPLACEMENT OF REPORTS CLUSTER

    Hi,
    i've read the noter reports_gueide_to_changed_functionality on OTN.
    On Page 5 ist stated that reports cluster is deprecated.
    Snippet:
    Oracle Application Server High Availability provides the industry’s most
    reliable, resilient, and fault-tolerant application server platform. Oracle
    Reports’ integration with OracleAS High Availability makes sure that your
    enterprise-reporting environment is extremely reliable and fault-tolerant.
    Since using OracleAS High Availability provides a centralized clustering
    mechanism and several cutting-edge features, Oracle Reports clustering is now
    deprecated.
    Please can anyone tell me, what is the best practice to replace reports cluster.
    It's really annoying that the clustering technology is changing in every version of reports!!!
    martin

    hello,
    in reality, reports server "clusters" was more a load balancing solution that a clustering (no shared queue or cache). since it is desirable to have one load-balancing/HA approach for the application server, reports server clustering is deprecated in 10gR2.
    we understand that this frequent change can cause some level of frustration, but it is our strong believe that unifying the HA "attack plan" for all of the app server components will utimatly benefit custoemrs in simpifying their topologies.
    the current best practice is to deploy LBRs (load-balancing routers) with sticky-routing capabilites to distribute requests across middletier nodes in an app-server cluster.
    several custoemrs in high-end environments have already used this kind of configuration to ensure optimal HA for their system.
    thanks,
    philipp

  • Best practice for updating ATWRT (Characteristic Value) in AUSP

    I've notice that when we change the Characteristic Value of a Classification, that it does not update in the MM record. We have to go into MM02 for each material number that references Char Value and manually change it for row in AUSP to get updated.
    Should i just create a report to Loop through and update table AUSP directly? Or is there a better way to do this via a function or BAPI etc? Wanting to know what best practice is recommended.

    Hi Scott
    You can use a BAPI to do that.
    Check the following thread:
    BAPI to update characteristics in Material master?
    BR
    Caetano

  • Best Practice Question - Business Logic in Value Objects?

    Just wondering what people's thoughts on best practices for setting properties of Value Objects.
    For instance, I have several getter/setters in one of my Value Objects with logic in the setter that uses the value to set values of other properties.
    For example, I have a Value Object that has the following properties:
    category (of type Category, which is another Value Object with properties "name" and "id")
    categoryId (of type int)
    categoryUpdated (of type Boolean)
    I have a collection of Category Objects in the Model. When I set the categoryId of this class, I set the "categoryUpdated" to true, and dispatch an CairngormEvent to that find the "category" with the specified "categoryId" and set the "category" property to this item.
    So what is the best practice? To simply make the "categoryId" a public variable, and create a new Event/Command to perform all this logic? Or is it ok to do it all in the Value Object setter?
    Thanks.

    Hi Eric,
    I can't speak for best practices, but the only logic I've ever added to a VO were getters: an example was a set of getters on an airline flight VO to get overall flight departure/arrival times/cities from an array of flight segments in a property of the VO.
    I feel uneasy (in the nicest possible way) about your VO for two reasons: firstly it has a strong dependency on bits of the Cairngorm framework to look up the category (and VOs normally don't need to depend on anything), and secondly the intent of Commands in Cairngorm is more to represent user gestures than to wire up VO properties (I often see people shoehorning stuff into Commands that might be better of as plain old business utility classes). I would rather see an UpdateCategoryCommand (that's what the user is trying to do?) that updates categoryId and hits a delegate to populate the category property.
    That said you might have a very good reason for doing this. Could you tell us where the code is that's setting categoryId, and if anything is using categoryUpdated?
    Cheers,
    Robin

  • Best practice for linking fields from multiple entity objects

    I am currently transitioning from PHP to ADF. I'm looking for the best practice for linking data from multiple entity objects.
    Example:
    EO 'REQUESTS' has fields: req_id, name, dt, his_stat_id, her_stat_id
    EO 'STATUSES' has fields: stat_id, short_txt_descr
    'REQUESTS' is linked to EO 'STATUSES' on: STATUSES.stat_id = REQUESTS.his_status_id
    'REQUESTS' is also linked to EO 'STATUSES' on: STATUSES.stat_id = REQUESTS.her_status_id
    REQUESTS.his_status_id is independent of REQUESTS.her_status_id
    When I create a VO for REQUESTS, I want to display: REQUESTS.name, REQUESTS.dt, STATUSES.short_txt_descr (for his_stat_id), STATUS.short_txt_descr (for her_stat_id)
    What is the best practice for accomplishing this? It appears I could do it a few different ways:
    1. Create the REQUESTS VO with a LOV for his_stat_id and her_stat_id
    2. Create the REQUESTS VO with the join to STATUSES performed within the query for the VO. This would require joining on the STATUSES EO twice (his_stat_id, her_stat_id)
    3. I just started reading about View Links - would that somehow do what I'm looking for?
    I also need to be able to update his_status_id and her_status_id through the by selecting a STATUSES.short_txt_descr from a dropdown.
    Any suggestions on how to approach such a stupidly simple task?
    Using jDeveloper 11.1.2.2.0 if that makes a difference in the solution.
    Thanks ahead of time,
    CJ

    CJ,
    I vote for solution 1 as it's just your use case. As you said you what to update the his_status_id and her_status_id through the by selecting a STATUSES.short_txt_descr by a drop down. This is exactly the LOV solution.
    ViewLinks are used fro master detail navigation (which you don't do here) and Joining the data make it difficult to update (and you still need a LOV for the drop down box.
    Timo

  • Best Practice For ID value On Components

    I was just wondering what the best practice was for setting the ID value on ADF components. I have seen that on naming containers they recommend the length of the ID value be 7 characters or less to minimize the amount of HTML that has to be sent to the client. Should we just keep all ID fields as their default values which are relatively short or is it better to give them meaningful values? Any guidance would be appreciated.
    Thanks.

    Hi,
    It depends on the usage. If you are using client listeners, where you want to get the id of the component to process, you can name them to have some meaning. However, there is no harm in keeping the default id as it is.
    -Arun

  • Best practice in migrating from e.g. x4100 to another x4100 (replacement)?

    Hi everyone,
    what is your experience of 'best practice' esp in terms of migrating data from a unit of x4100 to another x4100?
    Asking so because the particular one we are replacing is giving halt issues and thus need replacement.
    thanks,
    James

    948115 wrote:
    Dear All,
    This is Priya.
    We are using ODI 11.1.1.6 version.
    In my ODI project, we have separate installations for Dev, Test and Prod. i.e. Master repositories are not common between all the three. Now my code is ready in dev. Test environment is just installed with ODI and Master and Work repositories are created. Thats it
    Now, I need to know and understand what is the simple & best way to import the code from Dev and migrate it to test environment. Can some one brief the same as a step by step procedure in 5-6 lines? If this is the 1st time you are moving to QA, better export/import complete work repositories. If it is not the 1st time then create scenario of specific packages and export/import them to QA. In case of scenario you need not to bother about model/datastores. keep in mind that the logical schema name should be same in QA as used in your DEV.
    Some questions on current state.
    1. Do the id's of master and work repositories in Dev and Test need to be the same?It should be different.
    2. I usually see in export file a repository id with 999 and fail to understand what it is exactly. None of my master or work repositories are named with that id.It is required to ensure object uniqueness across several work repositories. For more understanding you can refer
    http://docs.oracle.com/cd/E14571_01/integrate.1111/e12643/export_import.htm
    http://odiexperts.com/odi-internal-id/
    3. Logical Architecture objects and context do not have an export option. What is the suitable alternative for this?If you are exporting topology then you will get the logical connection and context details. If you are not exporting topology then you need to manually create context and other physical connection/logical connection.
    >
    Thanks,
    Priya
    Edited by: 948115 on Jul 23, 2012 6:19 AM

  • Best Practices for Using Service Controller for Entity Framework Database

    I'm running into an issue in my first time creating a Web Service with a .NET backend with Azure. I designed a database in Entity Framework and had it create the models, but I couldn't create a controller for the table unless I made the model inherit from
    EntityData. Here's the catch, the Database Model has int Id, but EntityData has string Id, so, of course, I'm getting errors. What is best practice for what I'm trying to do?
    Michael DiLeo

    hi Michael,
    Thanks for you posting!
    Sorry for I am not totally understanding your issue. Maybe two points need your confirm:
    1. I confuse with the "Service controller"? IS your meaning MVC controller? Or ServiceController(http://www.codeproject.com/Articles/31688/Using-the-ServiceController-in-C-to-stop-and-start
    2.whether  The type of ID in the model is match to the database ? In other words, Is the type of IDin .edmx matched to the database?
    By the way, it seems that this issue is more related to EF. You could post this issue on EF discussion for better support.
    Thanks & Regards,
    Will
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Best Practices - Dynamic Ranking, Dimension Values to Return, etc.

    The pinned post says non-technical questions belong on the Business Forum. I can't find an Endeca-specific business forum. If there is one, please tell me where to find it.
    My question is about dynamic ranking and the initial display of only the top N dimension values with a "More..." option to see the rest of them.
    What's the current wisdom on this from a usability point of view? Use it, don't use it? If using it, show how many values initially?
    Or, if not using it, you instead set up a hierarchy of dimensions so that the user never has to look at 50 choices for something?
    This is not a technical question. What is the current wisdom? What are the best practices?
    Thanks!

    Dynamic ranking is a good choice only if all choices cannot be further grouped. In my practice most of the content can be normalized and restricted to a very limited set of options. Dynamic ranking with "more" is an easy way out and seems like a lazy take on content management.

  • Best Practices when replacing 2003 server R2 with a new domainname and server 2012 r2 on same lan network

    I have a small office (10 computers with five users) that have a Windows 2003 server that has a corrupted AD. Their 2003 server R2 is essentially a file server and provides authentication.  They purchased a new Dell 2012 R2 server.  
    It seems easier to me to just create a new domain (using their public domain name).  
    But I need as little office downtime. as possible . Therefore I would like to promote this server to its new domain on the same lan as the current domain server.  I plan to manually replicate the users and folder permissions.  Once done, I plan to
    remove the old server from the network and join the office computers to the new domain.  
    They also they are also running a legacy application that will require some tweaking by another tech. I have been hoping to prep the new domain prior to new legacy tech arriving.  That is why I would like both domain to co-exist temporarily. I have read
    that the major issues involved in this kind of temporary configuration will then be related to setting up dns.  They are using the firewall to provide dhcp.
    Are there any best practices documents for this situation?
    Or is there a better or simpler strategy?
    Gary Metz

    I followed below two links. I think it should be the same even though the links are 2008 R2 migration steps.
    http://kpytko.pl/active-directory-domain-services/adding-first-windows-server-2008-r2-domain-controller-within-windows-2003-network/
    http://blog.zwiegnet.com/windows-server/migrate-server-2003-to-2008r2-active-directory-and-fsmo-roles/
    Hope this help!

Maybe you are looking for

  • IF Statement in BI

    Hi BI Experts, Can we write the IF Statemenrt in BI 7.0 Query Designer. Please give me the reply. Thanks in advance. Regards, Anjali

  • Locks up on google, yahoo mail, running windows 7 on imac with bootcamp

    I'm running windows 7 on an imac with bootcamp. When I go to google or yahoo mail, I never seem to land. It seems to lock up. The links aren't active nor are the back buttons. When I close it, out it doesn't shut down, so I have to shut it down in ta

  • Issue with 10.9.2 looking NAS drive away from home network

    I have a NAS drive on my home network. When I am away from my home network my MBP running 10.9.2 keeps looking for and not find ing the drive. It keeps interupting my work flow every few minutes. How do I resolve this issue? it is very annoying.

  • Cascading Combo Box

    I have a page with 2 cascading Single Once Choice (SOC). Price list SOC and Product list SOC. The requirement is that a customer ID will be sent into the page via url parameters which will filter the dropdown value for Price List. Price list SOC will

  • Using 01V96 as a control surface.

    Hi, I am having some serious issues using my 01v96 in remote mode (via MIDI) as a control surface. The first thing is that when the 01v96 is listed on the setup page Logic continually outputs a C -2 note about once a second. It also outputs sysex dat