Persist and merge

Hi!
I am not clear about difference between persist() and merge() in EntityManager.
If i use persist(entity) two times in one conversation, then exception occurs.
But if i use persist(entity) first time, and second time use merge(entity), it does work well.
So can you explain differences between them?
Cheers!!!

persist() is for new objects (inserts) merge() is for existing objects (updates).
You should only call persist() for new objects the first time you persist them. It will make the new objects managed in the current transaction context to be inserted on commit or flush. You can call persist() on any object that is managed in the current transaction context, but not on detached objects.
merge() is only required to merge the changes from a detached object (such as serialized objects) into the current transaction context. If you read the object in the current transaction context, you should not call merge on it, it is already managed. After the merge the detached object will still be detached, only the changes in the managed object will be committed.
-- James : [http://www.eclipselink.org]

Similar Messages

  • JPA persist() or merge()

    Hi All,
    I would like to get clarification between using JPA persist() and merge() where there is a OneToMany EMPLOYEE table unidirectionally joint to ManyToOne TELEPHONE table.
    The code snippet for OneToMany Employee.java entity object is as follows:
    @Entity
    @IdClass(EmployeePK.class)
    @Table(name="EMPLOYEE", catalog="CorporationDB", schema="")
    public class Employee implements Serializable {  
    @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
        @JoinTable(name="EMPLOYEE_TELEPHONE", catalog="CorporationDB", schema="",
                   joinColumns={@JoinColumn(name="FIRSTNAME", referencedColumnName="FIRSTNAME"),
                                @JoinColumn(name="SURNAME", referencedColumnName="SURNAME"),
                                @JoinColumn(name="AGE", referencedColumnName="AGE"),
                                @JoinColumn(name="SEX", referencedColumnName="SEX")},
                   inverseJoinColumns={@JoinColumn(name="TELEPHONE_ID")})
            private Collection<Telephone> telephones = new ArrayList<Telephone>();
        public Collection<Telephone> getTelephones()
         return telephones;
        public void setTelephones(Collection<Telephone> telephones)
         this.telephones = telephones;
        }The corresponding detail for ManyToOne Telephone.java entity object is:
    @Entity
    @Table(name="TELEPHONE", catalog="CorporationDB", schema="")
    public class Telephone implements Serializable {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Column(name="ID")
        private int id;
        @Column(name="TELEPHONE")
        private String telephone;
        public void setTelephone(String telephone) {
            this.telephone = telephone;
        public String getTelephone() {
            return telephone;
        }I would like JPA to to ignore (not overwrite) existing record and only add newer unique telephone numbers. persist() does that except it is throwing the following exceptions and continually re-trying to insert the duplicate records:
    Local Exception Stack:
    *Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.1 (Build b60e-fcs (12/23/2008))): oracle.toplink.essentials.exceptions.DatabaseException*
    Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry Allan-Smith-20-M' for key 'PRIMARY'
    Error Code: 1062
    Call: INSERT INTO CorporationDB.EMPLOYEE (FIRSTNAME, SURNAME, AGE, SEX.....) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    *bind => [Allan, Smith, 20, M,....]*
    Query: InsertObjectQuery(finance.Employee@1d2d80c)
    JTS5054: Unexpected error occurred in after completion
    On the other hand, merge() ignores (does not add) duplicate Employee record (good) but it still duplicates the ManyToOne TELEPHONE table. Is it because of the OneToMany(cascade={CascadeType.ALL}} property in Employee.java which duplicates TELEPHONE records automatically? As a result, how to ensure that only unique OneToMany (EMPLOYEE) & ManyToOne (TELEPHONE) records are added once?
    persist() seems to work fine except that it is continually erroring out instead of skipping to the next new record.
    This Java EE 5 application is running properly.
    I am running JDK1.6.0_7, GF2.1 and MySQL on Windows XP.
    Thanks in advance,
    Jack

    I would recommend you continue to use TopLink Essentials as your JPA provider by setting your provider in your persistence.xml, or upgrading to EclipseLink and setting it as your provider. The latest WLS release also includes EclipseLink.
    James : http://www.eclipselink.org

  • Accessing two PDf documents and merging them

    Hi,
    I have and application where on click of a button, 2 pdfs are read from the server and merged into one pdf document. My pdf documents are placed in a folder in irj folder on server. For this i referred to the blog:
    /people/nagamohan.devisetty/blog/2008/05/05/merging-pdf-files-using-java-apis
    As per this blog, i created a java file.But I wrote the code written in the main method of this java file in the OnAction of the web dynpro view. So my java file just contains concat () for merging the pdfs. And from this view itself i created the object of the java file and called the concat (). But when i execute this application i get the error message stating "The system cannot find the path specified".
    Can anyone please help in this regard.
    Thanks & regards,
    Anupreet

    Hi,
    Was your previous application already web dynpro? Or did you include your concat fonctuinnality to a web dynpro application?
    From WD, if you want to write files, they are written by default in the server folder \usr\sap\J2E\JC00\j2ee\cluster\server0\persistent\developmentserver
    Check if you have rights to write out of this folder, in the portal.
    Yann

  • I'm in cycle mode, and 'merge' is clicked in preferences. However, when I record, my previous track data keeps getting overwritten. Does anyone know what I'm doing wrong. Interestingly, I can still see the data in the region.

    I'm in cycle mode, and 'merge' is clicked in preferences. However, when I record, my previous track data keeps getting overwritten. Does anyone know what I'm doing wrong. Interestingly, I can still see the data in the region.

    jamestait wrote:
    when I record, my previous track data keeps getting overwritten.
    since you didn't specify, are you recording in a single take?
    http://www.bulletsandbones.com/GB/GBFAQ.html#multipassrecording
    (Let the page FULLY load. The link to your answer is at the top of your screen)

  • [Forum FAQ] SharePoint 2013: Extracting values from a multi-value enabled lookup column and merge values to a multi-value enabled column

    For some business requirements, users want to extract values from a multi-value enabled lookup column
    and add items to another list based on each separate value. In contrast, others want to find duplicate values in the list and merge associated values to a multi-value enabled column and then
    add items to another list based on the merged value. All of these can be achieved using SharePoint Designer 2013 Workflow.
    How to extract values from a multi-value enabled lookup column and add items to another list based
    on each separate value using SharePoint Designer 2013.
    Important actions: Loop Shape; Utility Actions
    Three scenarios
    Things to note
    Steps to create Workflow
    How to merge values to a multi-value enabled column and add item to another list based on the
    merged value using SharePoint Designer 2013.
    Important actions: Call HTTP Web Service; Build Dictionary
    Things to note
    Steps to create Workflow
    How to
    extract values from a multi-value enabled lookup column and
    add items to another list based on each separate value using SharePoint Designer 2013.
    For example, they have three lists as below. They want to
    extract values from the Destinations column
    in Lookup2 and add items to Lookup3 based on each country and set Title to current item: ID.
    Lookup1:
    Title (Single line of text)
    Lookup2:
    Title (Single line of text), Destinations (Lookup; Get information from: Lookup1 in Title column).\
    Lookup3:
    Title (Single line of text), Country (Single line of text).
    Important action
    1. Loop Shape: SharePoint Designer 2013 support two types of loops: loop n times and loop with condition.
    Loops must also conform to the following rules:
    Loops must be within a stage, and stages cannot be within a loop.
    Steps may be within a loop.
    Loops may have only one entry and one exit point.
    2. Utility Actions: It contains many actions, such as ‘Extract Substring from Index of String’ and ‘Find substring in String’.
    Three scenarios
    We need to loop through the string returned from the look up column and look for commas. There are three
    scenarios:
    1.  No comma but string is non-empty so there is only one country.
    2.  At least one comma so there is at least two or more countries to loop.
    3.  In the loop we have consumed all the commas so we have found the last country. 
    Things to note
    There are two things to note:
    1. "Find string in string (output to Variable:index)"  will return -1 if doesn't find
    the searched for string.
    2. In the opening statement "Set Variable: Countries to Current Item:Destinations" set the return
    field as  "Lookup Values, Comma Delimited".
    Steps to create Workflow
    Create a custom list named Lookup1.
    Create a custom list named Lookup2, add column: Destinations (Lookup; Get information from: Lookup1 in Title column).
    Create a custom list named Lookup3, add column: Country (Single line of text).
    Create a workflow associated to Lookup2.
    Add conditions and actions:
    Start the workflow automatically when an item is created.
    Add item to Lookup2, then workflow will be started automatically and create multiple items to lookup3.
    See the below in workflow History List:
    How to merge values to a multi-value enabled column and add item to another list based on the
    merged value using SharePoint Designer 2013
    For example, they have three lists as below. They want to find duplicate values in the Title column in
    Lookup3 and merge country column to a multi-value enabled column and then add item to lookup2 and set the Title to Current Item: Title.
    Lookup1:
    Title (Single line of text)
    Lookup3:
    Title (Single line of text), Country (Single line of text).
    Lookup2:
    Title (Single line of text), Test (Single line of text).
    Important actions
    "Call HTTP Web Service"
    action: In SharePoint 2013 workflows, we can call a web service using a new action introduced in SharePoint 2013 named Call HTTP Web Service. This action
    is flexible and allows you to make simple calls to a web service easily, or, if needed, you can create more complex calls using HTTP verbs as well as allowing you to add HTTP headers.
    “Build Dictionary"
    action:
    The Dictionary variable type is a new variable type in the SharePoint 2013 Workflow.
    The following are the three actions specifically designed for the Dictionary variable type: Build Dictionary, Count Items in a Dictionary and Get an Item from a Dictionary.
    The "Call HTTP Web Service" workflow action would be useless without the new "Dictionary" workflow action.
    Things to note
    The
    HTTP URI is set to https://sitename/_api/web/lists/GetByTitle('listname')/items?$orderby=Id%20desc and the HTTP method is set to “GET”. Then the list will be sort by Id in descending order.
    Use Get
    d/results(0)/Id form
    Variable: ResponseContent (Output to
    Variable: maxid) to get the Max ID.
    Use Set
    Variable: minid to Current List:ID to get the Min ID.
    Use Copy from
    Variable: destianation , starting at
    1 (Output to
    Variable: destianation) to remove the space.
    Steps to create Workflow
    Create a custom list named Lookup1.
    Create a custom list named Lookup2, add column: Test (Single line of text).
    Create a custom list named Lookup3, add column: Country (Single line of text).
    Create a workflow associated to Lookup3.
    Add a new "Build Dictionary" action
    to define the http request header:
    Add a Call HTTP Web Serviceaction, click on
    this and paste your http request.
    To associate the
    RequestHeader variable, select the Call action property,
    set the
    RequestHeaders property to
    RequestHeader:
    In the Call action, click on
    response and associate the response to a new
    variable: ResponseContent (of type Dictionary).
    After the Call action add Get item from Dictionary action to get the Max ID.
    Add Set Workflow Variable action to get the Min ID.
    Add Loop Shape (Loop with Condition) to get all the duplicate titles and integrate them to a string.
    Create item in Lookup2.
    The final Stage should look like this:
    Start the workflow automatically when an item is created.
    Add item to Lookup3, then workflow will be started automatically and create item to lookup2.
    See the below in workflow History List:
    References
    SharePoint Designer 2013 - Extracting values from a multi-value enabled lookup column into a dictionary as separate items:
    http://social.technet.microsoft.com/Forums/en-US/97d34468-1b53-4741-88b0-958472f8ca9a/sharepoint-designer-2013-extracting-values-from-a-multivalue-enabled-lookup-column-into-a
    Workflow actions quick reference (SharePoint 2013 Workflow platform):
    http://msdn.microsoft.com/en-us/library/jj164026.aspx
    Understanding Dictionary actions in SharePoint Designer 2013:
    http://msdn.microsoft.com/en-us/library/office/jj554504.aspx
    Working with Web Services in SharePoint 2013 Workflows using SharePoint Designer 2013:
    http://msdn.microsoft.com/en-us/library/office/dn567558.aspx
    Calling the SharePoint 2013 Rest API from a SharePoint Designer Workflow:
    http://sergeluca.wordpress.com/2013/04/09/calling-the-sharepoint-2013-rest-api-from-a-sharepoint-designer-workflow/

    GREAT info, but it may be helpful to note that when replacing a portion of the variable "Countries" with a whitespace character, you may cause the workflow to fail in a few specific cases (certain lookup fields will not accept this and will automatically
    cancel).  I only found this out when recreating your workflow on a similar, but much more complex list set.  
    To resolve this issue, I used another utility action (Extract Substring from Index of List) to clear out the whitespace.  I configured it as "Copy from
    Variable: Countries, starting at
    1 (Output to Variable: Countries), which takes care of this issue in those few cases.
    Otherwise, WOW!  AWESOME JOB!  Thanks!  :)

  • I have just installed iTunes on my laptop and merged tracks under various artists to form one album but when I sync iTunes to my new ipod the tracks on some of the albums are appearing as single artists..... WHY????  I

    I Have just spent the best part of a week installing iTunes on my laptop, transferring over all my music and merging tracks by different artists on one album so that they all show as one album.   I have just plugged in my new ipod classic to sync all my music but the music has gone across in random tracks and split albums.... I really am losing the will to live and am about to throw both iPod and laptop out the window.... So SOMEBODY.... Please HELP.

    'The installer has insufficient privileges to modify this file C:\Program Files (x86)\Common Files\Apple\Apple Application Support\Web kit.resources\inspector\Images\Spinner Inactive Selected.gif.'
    That one's consistent with disk/file damage. The first thing I'd try with that is running a disk check (chkdsk) over your C drive.
    XP instructions in the following document: How to perform disk error checking in Windows XP
    Vista instructions in the following document: Check your hard disk for errors
    Windows 7 instructions in the following document: How to use CHKDSK (Check Disk)
    Select both Automatically fix file system errors and Scan for and attempt recovery of bad sectors, or use chkdsk /r (depending on which way you decide to go about doing this). You'll almost certainly have to schedule the chkdsk to run on startup. The scan should take quite a while ... if it quits after a few minutes or seconds, something's interfering with the scan.
    Does the chkdsk find/repair any damage? If so, can you get an install to go through properly afterwards?

  • Convert different types of files and merged them into one pdf

    Hi, everyone. I'm girl from China.
    There is folder containing severl files of different types, like doc, msg, jpeg etc.   And I want to convert and merge them into one pdf following a certain order. I know that PDFmaker can do that nicely, but the problem is that I have like 3000+ fodlders that requires the same work.
    I want to do it with VBA and Acrobat. I have a Acrobat XI Standard Version and a perfect license, by the way
    And I have got the code(Thanks, Karl Heinz Kremer) of merging two pdfs into one, but how can I convert them into pdf first?
    Thank you very much.
    If I can finish this, I would like to publish my code on this forum.

    Wow, that's great news. But how should I add the Action?
    1. There is no action named "Covert files into Pdf" in the tools panel....
    And if I write Javascript code to do this action. How should I write it?
    app.openDoc({
    cPath: "/c/temp/myPic.jpg",
    bUseConv: true
    These code only works when I specify the path of the file.
    If you know how, pls tell me..........

  • How can I open all my itunes libraries and merge them into one?

    Some of my music can't be opened by itunes because it says it is in another library.  As there are several of these and they won't open,I can't see where the songs I want are.  Therefore I would like to open ALL the libraries and merge them into one.  Thanks for any help.

    Hmm, read that post of Dave Sawyer's and thought well, that's Ok I have it on my iPod, but no, it's not there either.  Then resorted to Time Machine (not used for a few months (took it away with us when we evacuated to avoid Cyclone Yasi) only to find that is playing up also, and it doesn't appear to be anywhere there either!
    One thing leads on to another - Time Machine has only backed up to 3 months back; then there is nothing beyond!  yet there is tons of stuff on it.  Maybe it backs up the whole system each time, and not just the changes made inbetween times.   The prefs. won't appear and so I can't change the setup.
    All this just because of one sone!

  • I have 2 iTunes accounts and would like to eliminate 1 and merge all my purchases into ine

    Hello, I have two separate iTunes accounts.  Long story.........involving my kids.  Now, I´d like to eliminate one and merge all my purchases to the other without loosing everything.  Can this be done, how?

    Click here and follow the instructions.
    (107903)

  • I had an Apple ID and password with my hotmail acct.  The password stopped working, so I set up a new one with my me acct.  How can I access my old acct. and merge the two of them?

    I had an Apple ID and password with my hotmail acct.  The password stopped working, so I set up a new one with my me acct.  How can I access my old acct. and merge the two of them?

    https://iforgot.apple.com/cgi-bin/WebObjects/DSiForgot.woa/wa/iforgot?language=C A-EN&app_id=2417&newWindow=true&border=false

  • How do I merge my Apple address book with Google addresses and merge duplicates?

    How do I merge my Apple address book with Google addresses and merge duplicates?

    Hello Russell,
    Merging contacts...
    http://support.google.com/mail/bin/answer.py?hl=en&answer=165334
    Google Contacts Can Kill Duplicates in Bulk...
    http://lifehacker.com/5427716/google-contacts-can-kill-duplicates-in-bulk

  • Help required for slicing and merging file

    Hi,
    I am working on p2p downloading application based on Gnutella. Right now i am trying to implement downlaoding one file from many hosts at a time(like limewire does). i am able to connect to multiple host. but dont know how to downlaod and merge file for his purpose.
    i know how to download one file from single host. but dont know how to handle file coming from multiple hosts.
    if anyone having knowledge, please tell as soon as possble.

    Hi.
    thanks for the reply. Actually i had something same
    in my mind. but unfortunately i am quite week in
    serializtion and file stuff. If you could provide me
    with code snipet for this, or can just simulate in a
    fewer lines of code, it would be a great help for
    me...i have too much short time...
    i think i really have to study this file
    stuff..........You shouldn't use serialization. Just invent a protocol, and "normal" binary data.
    Kaj

  • Mapping with Match and Merge operater giving ORA-06550 error while deploy..

    Created a simplet mapping to source from Customer table to tstcustomer table thru' Match and Merge operator. The mapping validated successful but giving ORA-06550 line x column y error while deploying the mapping.
    It is a simple mapping consisting of source Customer table, Match and Merge operator, tstcustomer target table.
    Could anyone advise me on how to resolve this?

    The test mapping basically consists of :
    source table - sh.customers
    target table - tstcustomers (similar to sh.customers)
    Match-Merge operator.
    The mapping validation was successful but when attempt was made to deploy, its giving errors starting with ORA-06550.
    I saved the code and executed thru' SQL Plus and the error details are as follows:
    SQL> show errors;
    Errors for PACKAGE BODY MMTEST4:
    LINE/COL ERROR
    594/6 PL/SQL: Statement ignored
    594/37 PLS-00306: wrong number or types of arguments in call to 'RTRIM'
    601/6 PL/SQL: Statement ignored
    601/36 PLS-00306: wrong number or types of arguments in call to 'RTRIM'
    1017/655 PL/SQL: SQL Statement ignored
    30
    1020/27 PL/SQL: ORA-00942: table or view does not exist
    2163/6 PL/SQL: Statement ignored
    2163/43 PLS-00201: identifier 'CUSTOMERS_0_CUST_GENDER' must be declared
    2170/6 PL/SQL: Statement ignored
    LINE/COL ERROR
    2170/42 PLS-00201: identifier 'CUSTOMERS_0_COUNTRY_ID' must be declared
    2586/655 PL/SQL: SQL Statement ignored
    30
    2589/27 PL/SQL: ORA-00942: table or view does not exist
    SQL>
    For your info, the same mapping without Match-Merge Operator is getting deployed and executed successfully.
    But with Match-Merge operator, after setting Match bins, Match rules, Merge rules etc the mapping is validated successfully but errorring out while deployment.
    Pls advise on how to resolve this.
    I understand that the Match-Merge Operator gives Pl/Sql output from the documentation.
    thanks
    Naren.

  • Group and Merge Delimited List

    Hi All
    Is there a way we can sort the result of Group and Merge processor->Delimited list values ?
    I see none in the options and it seems sorting them in alphabetical order.
    Thanks,
    Sid

    Hi Sid,
    Yes, the "Delimited List" selection function in Group and Merge sorts the results into ascending alphabetical order. This was a deliberate decision so that the results of the processor are deterministic and agnostic of the order of the records entering the processor. It is not possible to change this sort order inside the processor but if required you can perform downstream post-processing of the data if you need to change the order.
    thanks,
    Nick

  • BPM Split and Merge

    Hi...
       I want to do scenario like file split and merge using BPM.
    for that i have used,
    1.Receive
    2.Transformation(1:N)
    3.Block(ForEach)
    4.Control
    5.EndBlock
    6.Transformation(N:1)
    7.Send.
    while executing the scenario, the message is going to the queue. In that it is showing the status as "Running".
    can you please tell if i did wrong in my scenario?

    > 1.Receive
    > 2.Transformation(1:N)
    > 3.Block(ForEach)
    > 4.Control
    > 5.EndBlock
    > 6.Transformation(N:1)
    > 7.Send.
    U are using an empty infinite block and hence it is in running state always. You dont need a block at all. after 1:n transformation, use the n:1 transformation and send. I know you must be doing a sample scenario. In reality you will have a send step usually for sending to another system line by line. That when you will need a block.
    VJ

Maybe you are looking for