Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8726929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:20:42+00:00 2026-06-13T08:20:42+00:00

I try to update existing data rows in database but i get that exception:

  • 0

I try to update existing data rows in database but i get that exception:

[EL Warning]: 2012-10-24 20:02:27.798--UnitOfWork(22664464)--Exception [EclipseLink-4002] (Eclipse Persistence Services -
2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '20-http://www.vilpra.lt/products/Foto/Aremikas/Katilas_zvake_big' for key 'PRIMARY' Error Code: 1062 Call: INSERT INTO x_links_media (image, link_id) VALUES (?, ?)  bind => [2 parameters bound] Query: InsertObjectQuery(database.entity.XLinksMedia[ xLinksMediaPK=database.entity.XLinksMediaPK[ linkId=20, image=http://www.link.lt/products.jpg ] ])

The main object class is look like code below. There is some variables with relation OneToMany.

package database.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

@Entity
@Table(name = "x_parser_links")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "XParserLinks.findAll", query = "SELECT x FROM XParserLinks x"),
    @NamedQuery(name = "XParserLinks.findByLinkId", query = "SELECT x FROM XParserLinks x WHERE x.linkId = :linkId"),
    @NamedQuery(name = "XParserLinks.findByPageId", query = "SELECT x FROM XParserLinks x WHERE x.pageId = :pageId"),
    @NamedQuery(name = "XParserLinks.findByLink", query = "SELECT x FROM XParserLinks x WHERE x.link = :link"),
    @NamedQuery(name = "XParserLinks.findByLevel", query = "SELECT x FROM XParserLinks x WHERE x.level = :level"),
    @NamedQuery(name = "XParserLinks.findByLinkType", query = "SELECT x FROM XParserLinks x WHERE x.linkType = :linkType"),
    @NamedQuery(name = "XParserLinks.findByCreateDate", query = "SELECT x FROM XParserLinks x WHERE x.createDate = :createDate"),
    @NamedQuery(name = "XParserLinks.findByDelDate", query = "SELECT x FROM XParserLinks x WHERE x.delDate = :delDate")})
public class XParserLinks implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "link_id")
    private Integer linkId;
    @Column(name = "page_id")
    private Integer pageId;
    @Column(name = "link")
    private String link;
    @Column(name = "level")
    private Integer level;
    @Column(name = "link_type")
    private Short linkType;
    @Column(name = "create_date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createDate;
    @Column(name = "del_date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date delDate;
    @JoinColumn(name = "tev_link_id")
    @OneToOne(cascade = CascadeType.ALL)
    private XParserLinks tevas;
    @OneToMany(mappedBy = "xParserLink", targetEntity = XLinksMedia.class, cascade = CascadeType.ALL)
    private List<XLinksMedia> fotos;
    @OneToMany(mappedBy = "xParserLink", targetEntity = XLinksVarchar.class, cascade = CascadeType.ALL)
    private List<XLinksVarchar> atributes;    

    public XParserLinks() {
    }

    public XParserLinks(Integer linkId) {
        this.linkId = linkId;
    }

    public Integer getLinkId() {
        return linkId;
    }

    public void setLinkId(Integer linkId) {
        this.linkId = linkId;
    }

    public Integer getPageId() {
        return pageId;
    }

    public void setPageId(Integer pageId) {
        this.pageId = pageId;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public Short getLinkType() {
        return linkType;
    }

    public void setLinkType(Short linkType) {
        this.linkType = linkType;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Date getDelDate() {
        return delDate;
    }

    public void setDelDate(Date delDate) {
        this.delDate = delDate;
    }

    public XParserLinks getTevas() {
        return tevas;
    }

    public void setTevas(XParserLinks tevas) {
        this.tevas = tevas;
    }

    public List<XLinksMedia> getFotos() {
        return fotos;
    }

    public void setFotos(List<XLinksMedia> fotos) {
        this.fotos = fotos;
    }

    public List<XLinksVarchar> getAtributes() {
        return atributes;
    }

    public void setAtributes(List<XLinksVarchar> atributes) {
        this.atributes = atributes;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (linkId != null ? linkId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof XParserLinks)) {
            return false;
        }
        XParserLinks other = (XParserLinks) object;
        if ((this.linkId == null && other.linkId != null) || (this.linkId != null && !this.linkId.equals(other.linkId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "database.entity.XParserLinks[ linkId=" + linkId + " ]";
    }
}

And here is code where I want to proceed data. XParserLinks object is the man object like code above. In this example I check if object do not have his primary key LinkId then create new object with persist, but else just update object and his values, but I get exception like I mean before when I want to update existing object.

        XParserLinks e = entry.getValue();

        if (e.getLinkId() == null) {
            try {
                TarpineManager.startTransaction();

                TarpineManager.persist(e);

                TarpineManager.commitTransaction();

            } catch (Exception ex) {
                ex.printStackTrace();
                if (TarpineManager.getInstance().getTransaction().isActive()) {
                    TarpineManager.rollbackTransaction();
                }
            }
        } else {

            try {

                TarpineManager.startTransaction();

                TarpineManager.commitTransaction();

            } catch (Exception ex) {
                ex.printStackTrace();
                if (TarpineManager.getInstance().getTransaction().isActive()) {
                    TarpineManager.rollbackTransaction();
                }
            }

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:20:43+00:00Added an answer on June 13, 2026 at 8:20 am

    Are you, by any chance, creating your entity and setting its Id by force? I see your class has a setLinkId(Integer linkId) method on it.

    First of all, you should be using merge instead of persist. Now, whit this in mind, the exception is also being thrown by the merge method because JPA can’t define if the entity you want to persist is a new one or it’s a previosuly fetched one, because the states in the lifecycle aren’t the same.

    If you create an object and set its id, that entity has the state new, but if you fetched the entity before it should have a detached state. When merged, a detached entity will be correctly updated but a new entity will be persisted and, since the id is taken, the exception is thrown.

    You have the entity’s ID, so you better fetch them before, update the object and then merge them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to update database table and this is my code: public void updatefiletable(String
I try to update a table using another table. I get the error number
I have this code for update: public Boolean update() { try { data.put(ContactsContract.Groups.SHOULD_SYNC, true);
I need to update millions of rows as part of my next release, but
Because of legacy data which is not available in the database but some external
There is an existing table in database where I want to update one column.
I try to update a column in an table with the following query. In
I try to update my profile image and use this code: $connection->post('account/update_profile_image', array('image' =>
I try to update a project from SVN (I have a fresh install of
I have a DAO class which I'm using to try select/update/insert with hibernate and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.