users@glassfish.java.net

getting always ORA-00001 Error when i try to persist a 1:n relation

From: <glassfish_at_javadesktop.org>
Date: Sat, 20 Oct 2007 11:00:25 PDT

Hi!

I always get an ORA-00001 Error (unique constrain) when i try to persist a normal object which has a Collection of Another object:

This is the Code to persist:
 try
        {
            Context ctx = (Context) new InitialContext().lookup("java:comp/env");
            EntityManager em = (EntityManager) ctx.lookup("persistence/LogicalName");
            utx.begin();
            em.persist(input);
             em.flush();
            utx.commit();
           
       
     
            em.close();
            
       
        }

It seems that i always get an ID from the Sequence which is already used.
Please help me i donĀ“t know where i can find my problem....

the First object (sorry for the long Code):

/*
 * EbtRevisions.java
 *
 * Created on 3. Oktober 2007, 09:51
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package at.kelag.ebt.database;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Date;
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.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entity class EbtRevisions
 *
 * @author joerg
 */
@Entity
@Table(name = "EBT_REVISIONS")
@NamedQueries(
            {
        @NamedQuery(name = "EbtRevisions.findById", query = "SELECT e FROM EbtRevisions e WHERE e.id = :id"),
        @NamedQuery(name = "EbtRevisions.findByB1", query = "SELECT e FROM EbtRevisions e WHERE e.b1 = :b1"),
        @NamedQuery(name = "EbtRevisions.findByB2", query = "SELECT e FROM EbtRevisions e WHERE e.b2 = :b2"),
        @NamedQuery(name = "EbtRevisions.findByB3", query = "SELECT e FROM EbtRevisions e WHERE e.b3 = :b3"),
        @NamedQuery(name = "EbtRevisions.findByStartdate", query = "SELECT e FROM EbtRevisions e WHERE e.startdate = :startdate"),
        @NamedQuery(name = "EbtRevisions.findByEnddate", query = "SELECT e FROM EbtRevisions e WHERE e.enddate = :enddate"),
        @NamedQuery(name = "EbtRevisions.findByCreator", query = "SELECT e FROM EbtRevisions e WHERE e.creator = :creator"),
        @NamedQuery(name = "EbtRevisions.findByCommunication", query = "SELECT e FROM EbtRevisions e WHERE e.communication = :communication"),
        @NamedQuery(name = "EbtRevisions.findBySubject", query = "SELECT e FROM EbtRevisions e WHERE e.subject = :subject"),
        @NamedQuery(name = "EbtRevisions.findByComments", query = "SELECT e FROM EbtRevisions e WHERE e.comments = :comments"),
        @NamedQuery(name = "EbtRevisions.findByCreationdate", query = "SELECT e FROM EbtRevisions e WHERE e.creationdate = :creationdate"),
        @NamedQuery(name = "EbtRevisions.findByStarttime", query = "SELECT e FROM EbtRevisions e WHERE e.starttime = :starttime"),
        @NamedQuery(name = "EbtRevisions.findByEndtime", query = "SELECT e FROM EbtRevisions e WHERE e.endtime = :endtime"),
        @NamedQuery(name = "EbtRevisions.findByStatus", query = "SELECT e FROM EbtRevisions e WHERE e.status = :status"),
        @NamedQuery(name = "EbtRevisions.findByRestrictions", query = "SELECT e FROM EbtRevisions e WHERE e.restrictions = :restrictions")
    })
public class EbtRevisions implements Serializable
{

    @Id
    @GeneratedValue(generator="rev_seq")

    @SequenceGenerator(name="rev_seq",sequenceName="EBT_REVISIONS_SEQ", allocationSize=1)
    @Column(name = "ID", nullable = false)
    private BigDecimal id;

    @Column(name = "B1", nullable = false)
    private String b1;

    @Column(name = "B2", nullable = false)
    private String b2;

    @Column(name = "B3", nullable = false)
    private String b3;

    @Column(name = "STARTDATE", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date startdate;

    @Column(name = "ENDDATE", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date enddate;

    @Column(name = "CREATOR", nullable = false)
    private String creator;

    @Column(name = "COMMUNICATION", nullable = false)
    private String communication;

    @Column(name = "SUBJECT", nullable = false)
    private String subject;

    @Column(name = "COMMENTS", nullable = false)
    private String comments;

    @Column(name = "CREATIONDATE", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date creationdate;

    @Column(name = "STARTTIME", nullable = false)
    private String starttime;

    @Column(name = "ENDTIME", nullable = false)
    private String endtime;

    @Column(name = "STATUS", nullable = false)
    private String status;

    @Lob
    @Column(name = "CONNECTION")
    private String connection;

    @Column(name = "RESTRICTIONS")
    private String restrictions;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "did")
    private Collection<EbtDocuments> ebtDocumentsCollection;
    
    /** Creates a new instance of EbtRevisions */
    public EbtRevisions()
    {
    }

    /**
     * Creates a new instance of EbtRevisions with the specified values.
     * @param id the id of the EbtRevisions
     */
    public EbtRevisions(BigDecimal id)
    {
        this.id = id;
    }

    /**
     * Creates a new instance of EbtRevisions with the specified values.
     * @param id the id of the EbtRevisions
     * @param b1 the b1 of the EbtRevisions
     * @param b2 the b2 of the EbtRevisions
     * @param b3 the b3 of the EbtRevisions
     * @param startdate the startdate of the EbtRevisions
     * @param enddate the enddate of the EbtRevisions
     * @param creator the creator of the EbtRevisions
     * @param communication the communication of the EbtRevisions
     * @param subject the subject of the EbtRevisions
     * @param comments the comments of the EbtRevisions
     * @param creationdate the creationdate of the EbtRevisions
     * @param starttime the starttime of the EbtRevisions
     * @param endtime the endtime of the EbtRevisions
     * @param status the status of the EbtRevisions
     */
    public EbtRevisions(BigDecimal id, String b1, String b2, String b3, Date startdate, Date enddate, String creator, String communication, String subject, String comments, Date creationdate, String starttime, String endtime, String status)
    {
        this.id = id;
        this.b1 = b1;
        this.b2 = b2;
        this.b3 = b3;
        this.startdate = startdate;
        this.enddate = enddate;
        this.creator = creator;
        this.communication = communication;
        this.subject = subject;
        this.comments = comments;
        this.creationdate = creationdate;
        this.starttime = starttime;
        this.endtime = endtime;
        this.status = status;
    }

    /**
     * Gets the id of this EbtRevisions.
     * @return the id
     */
    public BigDecimal getId()
    {
        return this.id;
    }

    /**
     * Sets the id of this EbtRevisions to the specified value.
     * @param id the new id
     */
    public void setId(BigDecimal id)
    {
        this.id = id;
    }

    /**
     * Gets the b1 of this EbtRevisions.
     * @return the b1
     */
    public String getB1()
    {
        return this.b1;
    }

    /**
     * Sets the b1 of this EbtRevisions to the specified value.
     * @param b1 the new b1
     */
    public void setB1(String b1)
    {
        this.b1 = b1;
    }

    /**
     * Gets the b2 of this EbtRevisions.
     * @return the b2
     */
    public String getB2()
    {
        return this.b2;
    }

    /**
     * Sets the b2 of this EbtRevisions to the specified value.
     * @param b2 the new b2
     */
    public void setB2(String b2)
    {
        this.b2 = b2;
    }

    /**
     * Gets the b3 of this EbtRevisions.
     * @return the b3
     */
    public String getB3()
    {
        return this.b3;
    }

    /**
     * Sets the b3 of this EbtRevisions to the specified value.
     * @param b3 the new b3
     */
    public void setB3(String b3)
    {
        this.b3 = b3;
    }

    /**
     * Gets the startdate of this EbtRevisions.
     * @return the startdate
     */
    public Date getStartdate()
    {
        return this.startdate;
    }

    /**
     * Sets the startdate of this EbtRevisions to the specified value.
     * @param startdate the new startdate
     */
    public void setStartdate(Date startdate)
    {
        this.startdate = startdate;
    }

    /**
     * Gets the enddate of this EbtRevisions.
     * @return the enddate
     */
    public Date getEnddate()
    {
        return this.enddate;
    }

    /**
     * Sets the enddate of this EbtRevisions to the specified value.
     * @param enddate the new enddate
     */
    public void setEnddate(Date enddate)
    {
        this.enddate = enddate;
    }

    /**
     * Gets the creator of this EbtRevisions.
     * @return the creator
     */
    public String getCreator()
    {
        return this.creator;
    }

    /**
     * Sets the creator of this EbtRevisions to the specified value.
     * @param creator the new creator
     */
    public void setCreator(String creator)
    {
        this.creator = creator;
    }

    /**
     * Gets the communication of this EbtRevisions.
     * @return the communication
     */
    public String getCommunication()
    {
        return this.communication;
    }

    /**
     * Sets the communication of this EbtRevisions to the specified value.
     * @param communication the new communication
     */
    public void setCommunication(String communication)
    {
        this.communication = communication;
    }

    /**
     * Gets the subject of this EbtRevisions.
     * @return the subject
     */
    public String getSubject()
    {
        return this.subject;
    }

    /**
     * Sets the subject of this EbtRevisions to the specified value.
     * @param subject the new subject
     */
    public void setSubject(String subject)
    {
        this.subject = subject;
    }

    /**
     * Gets the comments of this EbtRevisions.
     * @return the comments
     */
    public String getComments()
    {
        return this.comments;
    }

    /**
     * Sets the comments of this EbtRevisions to the specified value.
     * @param comments the new comments
     */
    public void setComments(String comments)
    {
        this.comments = comments;
    }

    /**
     * Gets the creationdate of this EbtRevisions.
     * @return the creationdate
     */
    public Date getCreationdate()
    {
        return this.creationdate;
    }

    /**
     * Sets the creationdate of this EbtRevisions to the specified value.
     * @param creationdate the new creationdate
     */
    public void setCreationdate(Date creationdate)
    {
        this.creationdate = creationdate;
    }

    /**
     * Gets the starttime of this EbtRevisions.
     * @return the starttime
     */
    public String getStarttime()
    {
        return this.starttime;
    }

    /**
     * Sets the starttime of this EbtRevisions to the specified value.
     * @param starttime the new starttime
     */
    public void setStarttime(String starttime)
    {
        this.starttime = starttime;
    }

    /**
     * Gets the endtime of this EbtRevisions.
     * @return the endtime
     */
    public String getEndtime()
    {
        return this.endtime;
    }

    /**
     * Sets the endtime of this EbtRevisions to the specified value.
     * @param endtime the new endtime
     */
    public void setEndtime(String endtime)
    {
        this.endtime = endtime;
    }

    /**
     * Gets the status of this EbtRevisions.
     * @return the status
     */
    public String getStatus()
    {
        return this.status;
    }

    /**
     * Sets the status of this EbtRevisions to the specified value.
     * @param status the new status
     */
    public void setStatus(String status)
    {
        this.status = status;
    }

    /**
     * Gets the connection of this EbtRevisions.
     * @return the connection
     */
    public String getConnection()
    {
        return this.connection;
    }

    /**
     * Sets the connection of this EbtRevisions to the specified value.
     * @param connection the new connection
     */
    public void setConnection(String connection)
    {
        this.connection = connection;
    }

    /**
     * Gets the restrictions of this EbtRevisions.
     * @return the restrictions
     */
    public String getRestrictions()
    {
        return this.restrictions;
    }

    /**
     * Sets the restrictions of this EbtRevisions to the specified value.
     * @param restrictions the new restrictions
     */
    public void setRestrictions(String restrictions)
    {
        this.restrictions = restrictions;
    }

    /**
     * Gets the ebtDocumentsCollection of this EbtRevisions.
     * @return the ebtDocumentsCollection
     */
    public Collection<EbtDocuments> getEbtDocumentsCollection()
    {
        return this.ebtDocumentsCollection;
    }

    /**
     * Sets the ebtDocumentsCollection of this EbtRevisions to the specified value.
     * @param ebtDocumentsCollection the new ebtDocumentsCollection
     */
    public void setEbtDocumentsCollection(Collection<EbtDocuments> ebtDocumentsCollection)
    {
        this.ebtDocumentsCollection = ebtDocumentsCollection;
    }

    /**
     * Returns a hash code value for the object. This implementation computes
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    /**
     * Determines whether another object is equal to this EbtRevisions. The result is
     * <code>true</code> if and only if the argument is not null and is a EbtRevisions object that
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @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 EbtRevisions)) {
            return false;
        }
        EbtRevisions other = (EbtRevisions)object;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false;
        return true;
    }

    /**
     * Returns a string representation of the object. This implementation constructs
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString()
    {
        return "at.kelag.ebt.database.EbtRevisions[id=" + id + "]";
    }
    
}


and the Second Object :
/*
 * EbtDocuments.java
 *
 * Created on 31. August 2007, 12:03
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package at.kelag.ebt.database;

import java.io.Serializable;
import java.math.BigDecimal;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 * Entity class EbtDocuments
 *
 * @author joerg
 */
@Entity
@Table(name = "EBT_DOCUMENTS")
@NamedQueries(
            {
        @NamedQuery(name = "EbtDocuments.findById", query = "SELECT e FROM EbtDocuments e WHERE e.id = :id"),
        @NamedQuery(name = "EbtDocuments.findByFilename", query = "SELECT e FROM EbtDocuments e WHERE e.filename = :filename"),
        @NamedQuery(name = "EbtDocuments.findByCreator", query = "SELECT e FROM EbtDocuments e WHERE e.creator = :creator"),
        @NamedQuery(name = "EbtDocuments.findByType", query = "SELECT e FROM EbtDocuments e WHERE e.type = :type")
    })
public class EbtDocuments implements Serializable
{

    @Id
    @GeneratedValue(generator="data_seq")
    @SequenceGenerator(name="data_seq",sequenceName="EBT_DATA_SEQ", allocationSize=1)
    @Column(name = "ID", nullable = false)
    private BigDecimal id;

    @Column(name = "FILENAME", nullable = false)
    private String filename;

    @Lob
    @Column(name = "DATA", nullable = false)
    private Serializable data;

    @Column(name = "CREATOR", nullable = false)
    private String creator;

    @Column(name = "TYPE", nullable = false)
    private String type;

    @JoinColumn(name = "DID")
    @ManyToOne
    private EbtRevisions did;
    
    /** Creates a new instance of EbtDocuments */
    public EbtDocuments()
    {
    }

    /**
     * Creates a new instance of EbtDocuments with the specified values.
     * @param id the id of the EbtDocuments
     */
    public EbtDocuments(BigDecimal id)
    {
        this.id = id;
    }

    /**
     * Creates a new instance of EbtDocuments with the specified values.
     * @param id the id of the EbtDocuments
     * @param filename the filename of the EbtDocuments
     * @param data the data of the EbtDocuments
     * @param creator the creator of the EbtDocuments
     * @param type the type of the EbtDocuments
     */
    public EbtDocuments(BigDecimal id, String filename, Serializable data, String creator, String type)
    {
        this.id = id;
        this.filename = filename;
        this.data = data;
        this.creator = creator;
        this.type = type;
    }

    /**
     * Gets the id of this EbtDocuments.
     * @return the id
     */
    public BigDecimal getId()
    {
        return this.id;
    }

    /**
     * Sets the id of this EbtDocuments to the specified value.
     * @param id the new id
     */
    public void setId(BigDecimal id)
    {
        this.id = id;
    }

    /**
     * Gets the filename of this EbtDocuments.
     * @return the filename
     */
    public String getFilename()
    {
        return this.filename;
    }

    /**
     * Sets the filename of this EbtDocuments to the specified value.
     * @param filename the new filename
     */
    public void setFilename(String filename)
    {
        this.filename = filename;
    }

    /**
     * Gets the data of this EbtDocuments.
     * @return the data
     */
    public Serializable getData()
    {
        return this.data;
        
    }

    /**
     * Sets the data of this EbtDocuments to the specified value.
     * @param data the new data
     */
    public void setData(Serializable data)
    {
        this.data = data;
    }

    /**
     * Gets the creator of this EbtDocuments.
     * @return the creator
     */
    public String getCreator()
    {
        return this.creator;
    }

    /**
     * Sets the creator of this EbtDocuments to the specified value.
     * @param creator the new creator
     */
    public void setCreator(String creator)
    {
        this.creator = creator;
    }

    /**
     * Gets the type of this EbtDocuments.
     * @return the type
     */
    public String getType()
    {
        return this.type;
    }

    /**
     * Sets the type of this EbtDocuments to the specified value.
     * @param type the new type
     */
    public void setType(String type)
    {
        this.type = type;
    }

    /**
     * Gets the did of this EbtDocuments.
     * @return the did
     */
    public EbtRevisions getDid()
    {
        return this.did;
    }

    /**
     * Sets the did of this EbtDocuments to the specified value.
     * @param did the new did
     */
    public void setDid(EbtRevisions did)
    {
        this.did = did;
    }

    /**
     * Returns a hash code value for the object. This implementation computes
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    /**
     * Determines whether another object is equal to this EbtDocuments. The result is
     * <code>true</code> if and only if the argument is not null and is a EbtDocuments object that
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @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 EbtDocuments)) {
            return false;
        }
        EbtDocuments other = (EbtDocuments)object;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false;
        return true;
    }

    /**
     * Returns a string representation of the object. This implementation constructs
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString()
    {
        return "at.kelag.ebt.database.EbtDocuments[id=" + id + "]";
    }
    
}
[Message sent by forum member 'josh8224' (josh8224)]

http://forums.java.net/jive/thread.jspa?messageID=241369