Java 传递给持久化的JPA错误分离实体

Java 传递给持久化的JPA错误分离实体,java,hibernate,jpa,Java,Hibernate,Jpa,我在提交表单时遇到以下错误: org.hibernate.PersistentObjectException:传递给的分离实体 persist:com.project.pmet.model.Account;嵌套异常是 javax.persistence.PersistenceException: org.hibernate.PersistentObjectException:传递给的分离实体 坚持:com.project.stock.business.offer.Tarif 优惠: 日志错误:

我在提交表单时遇到以下错误:

org.hibernate.PersistentObjectException:传递给的分离实体 persist:com.project.pmet.model.Account;嵌套异常是 javax.persistence.PersistenceException: org.hibernate.PersistentObjectException:传递给的分离实体 坚持:com.project.stock.business.offer.Tarif

优惠:

日志错误:


我做错了什么?

如果您试图持久化一个新实体Tarif,那么请检查Tarif自动生成的id不在数据库中。看起来您试图持久化一个新实体,而持久化上下文已包含具有给定id的实体


如果要更新Tarif,请加载实体,然后更新或合并实体。

更新时使用的代码是什么?
/**
 * Offer.
 */
@Entity
@Table( name = "stock_offer" )
public class Offer extends StockEntityBean<Offer> implements Serializable
{

    /** The Constant serialVersionUID. */
    private static final long       serialVersionUID  = -6390433796484715419L;

    /** Sequence name. */
    private static final String     JPA_SEQUENCE_NAME = "stock_offer_sequence";

    /** Unique value. */
    private static final String     JPA_COLUMN_NAME   = "stock_offer_id";

    /** The _id. */
    private Integer                 _id;

    /** The _str name. */
    private String                  _strName;

    /** The _str description. */
    private String                  _strDescription;

    /** The _str statut. */
    private String                  _strStatut;

    /** The PRODUCT. */
    private Product                 _product;

    /** The _nMinTickets. */
    private Integer                 _nMinTickets;

    /** The _nMaxTickets. */
    private Integer                 _nMaxTickets;

    /** The _attribute list. */
    private Set<OfferAttribute>     _attributeList;

    /** The _attribute date list. */
    private Set<OfferAttributeDate> _attributeDateList;

    /** The _attribute num list. */
    private Set<OfferAttributeNum>  _attributeNumList;

    /** The tarifs */
    private Set<Tarif>              _tarifs;

    /*
     * @Transient private Provider _partner;
     */
    /**
     *
     * Creates a new Offer.java object.
     */
    public Offer( )
    {
        super( );
        _product = new Product( );
        _attributeDateList = new HashSet<OfferAttributeDate>( );
        _attributeList = new HashSet<OfferAttribute>( );
        _attributeNumList = new HashSet<OfferAttributeNum>( );
        _tarifs = new HashSet<Tarif>( );
    }

    /**
     *
     * Creates a new Offer.java object.
     *
     * @param category
     *            category
     */
    public Offer( Category category )
    {
    }

    /**
     * Return offer id.
     *
     * @return offer id
     */
    @Override
    @TableGenerator( table = StockJPAUtils.SEQUENCE_TABLE_NAME, name = JPA_SEQUENCE_NAME, pkColumnValue = JPA_COLUMN_NAME, allocationSize = 1 )
    @Id
    @GeneratedValue( strategy = GenerationType.TABLE, generator = JPA_SEQUENCE_NAME )
    @Column( name = "id_offer" )
    public Integer getId( )
    {
        return _id;
    }

    /**
     * Set the offer id.
     *
     * @param idOffer
     *            the offer id
     */
    @Override
    public void setId( Integer idOffer )
    {
        _id = idOffer;
    }

    /**
     * Return the offer name.
     *
     * @return the name
     */
    @Column( name = "name" )
    public String getName( )
    {
        return _strName;
    }

    /**
     * Set the category name.
     *
     * @param name
     *            the offer name
     */
    public void setName( String name )
    {
        _strName = name;
    }

    /**
     * Return the offer description.
     *
     * @return the description
     */
    @Column( name = "description" )
    public String getDescription( )
    {
        return _strDescription;
    }

    /**
     * Set the category description.
     *
     * @param description
     *            the offer description
     */
    public void setDescription( String description )
    {
        _strDescription = description;
    }

    /**
     * Return the PRODUCT.
     *
     * @return the PRODUCT
     */
    @ManyToOne( optional = true, fetch = FetchType.EAGER )
    @JoinColumn( name = "product_id" )
    public Product getProduct( )
    {
        return _product;
    }

    /**
     * Set the PRODUCT.
     *
     * @param product
     *            the PRODUCT
     */
    public void setProduct( Product product )
    {
        _product = product;
    }

    /**
     * Return the minimal number of tickets.
     *
     * @return _nMinTickets
     */
    @Column( name = "min_tickets" )
    public Integer getMinTickets( )
    {
        return _nMinTickets;
    }

    /**
     * Set the minimal number of tickets.
     *
     * @param minTickets
     *            the minimal number of tickets
     */
    public void setMinTickets( Integer minTickets )
    {
        _nMinTickets = minTickets;
    }

    /**
     * Return the minimal number of tickets.
     *
     * @return _nMinTickets
     */
    @Column( name = "max_tickets" )
    public Integer getMaxTickets( )
    {
        return _nMaxTickets;
    }

    /**
     * Set the maximum number of tickets.
     *
     * @param nMaxTickets
     *            the maximum number of tickets
     */
    public void setMaxTickets( Integer nMaxTickets )
    {
        this._nMaxTickets = nMaxTickets;
    }

    /**
     * Returns dynamic attributes list.
     *
     * @return dynamic attributes list
     */
    @Override
    @OneToMany( cascade = { CascadeType.ALL }, mappedBy = "owner", orphanRemoval = true, fetch = FetchType.EAGER )
    public Set<OfferAttribute> getAttributeList( )
    {
        return _attributeList;
    }

    /**
     * Sets the attribute list.
     *
     * @param stringAttribute
     *            the new attribute list
     */
    public void setAttributeList( Set<OfferAttribute> stringAttribute )
    {
        _attributeList = stringAttribute;
    }

    /**
     * Returns dynamic attributes list.
     *
     * @return dynamic attributes list
     */
    @Override
    @OneToMany( cascade = { CascadeType.ALL }, mappedBy = "owner", orphanRemoval = true, fetch = FetchType.EAGER )
    public Set<OfferAttributeDate> getAttributeDateList( )
    {
        return _attributeDateList;
    }

    /**
     * Sets the attribute date list.
     *
     * @param dateAttribute
     *            the new attribute date list
     */
    public void setAttributeDateList( Set<OfferAttributeDate> dateAttribute )
    {
        _attributeDateList = dateAttribute;
    }

    /**
     * Returns dynamic attributes list.
     *
     * @return dynamic attributes list
     */
    @Override
    @OneToMany( cascade = { CascadeType.ALL }, mappedBy = "owner", orphanRemoval = true, fetch = FetchType.EAGER )
    public Set<OfferAttributeNum> getAttributeNumList( )
    {
        return _attributeNumList;
    }

    /**
     * Sets the attribute num list.
     *
     * @param numAttribute
     *            the new attribute num list
     */
    public void setAttributeNumList( Set<OfferAttributeNum> numAttribute )
    {
        _attributeNumList = numAttribute;
    }

    /**
     * Sets the statut.
     *
     * @param statut
     *            the statut to set
     */
    public void setStatut( String statut )
    {
        _strStatut = statut;
    }

    /**
     * Gets the statut.
     *
     * @return the statut
     */
    public String getStatut( )
    {
        return _strStatut;
    }

    @OneToMany( cascade = { CascadeType.ALL }, orphanRemoval = true, fetch = FetchType.EAGER, mappedBy = "offer" )
    public Set<Tarif> getTarifs( )
    {
        return _tarifs;
    }

    public void setTarifs( Set<Tarif> tarifs )
    {
        this._tarifs = tarifs;
    }

}
@Entity
@Table( name = "stock_tarif" )
public class Tarif implements Serializable
{
    /** Sequence name. */
    private static final String JPA_SEQUENCE_NAME = "stock_tarif_sequence";

    /** Unique value. */
    private static final String JPA_COLUMN_NAME   = "stock_tarif_id";

    /** The _id. */
    private Integer             _id;

    /** The _n quantity. */
    private Integer             _nQuantity;

    /** The _n quantity. */
    private Integer             _nQuantityCanopee;

    /** The _type. */
    private OfferGenre          _type;

    private BigDecimal          _price;

    private Integer             _initialQuantity;

    private Offer               _offer;

    /**
     *
     * Creates a new Tarif.java object.
     */
    public Tarif( )
    {
        super( );
        _type = new OfferGenre( );
        _offer = new Offer( );
    }

  //  @TableGenerator( table = StockJPAUtils.SEQUENCE_TABLE_NAME, name = JPA_SEQUENCE_NAME, pkColumnValue = JPA_COLUMN_NAME, allocationSize = 1 )
    @Id
   // @GeneratedValue( strategy = GenerationType.TABLE, generator = JPA_SEQUENCE_NAME )
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column( name = "id_tarif", updatable = false, nullable = false )
    public Integer getId( )
    {
        return _id;
    }

    public void setId( Integer idTarif )
    {
        _id = idTarif;
    }

    @Column( name = "quantity" )
    public Integer getQuantity( )
    {
        return _nQuantity;
    }

    public void setQuantity( Integer nQuantity )
    {
        _nQuantity = nQuantity;
    }

    @Column( name = "quantityCanopee" )
    public Integer getQuantityCanopee( )
    {
        return _nQuantityCanopee;
    }

    public void setQuantityCanopee( Integer quantityCanopee )
    {
        _nQuantityCanopee = quantityCanopee;
    }

    @Column( name = "price" )
    public BigDecimal getPrice( )
    {
        return _price;
    }

    public void setPrice( BigDecimal price )
    {
        this._price = price;
    }

    @Column( name = "initialQuantity" )
    public Integer getInitialQuantity( )
    {
        return _initialQuantity;
    }

    public void setInitialQuantity( Integer initialQuantity )
    {
        this._initialQuantity = initialQuantity;
    }

    @ManyToOne( fetch = FetchType.LAZY )
    @JoinColumn( name = "offer_id" )
    public Offer getOffer( )
    {
        return _offer;
    }

    public void setOffer( Offer offer )
    {
        this._offer = offer;
    }

    @ManyToOne( fetch = FetchType.EAGER )
    @JoinColumn( name = "offer_genre_id" )
    public OfferGenre getType( )
    {
        return _type;
    }

    public void setType( OfferGenre type )
    {
        _type = type;
    }
}
Hibernate: 
    update
        stock_sequences 
    set
        next_val=?  
    where
        next_val=? 
        and sequence_name=?
26/04/18 12:14:29 ERROR [http-nio-9090-exec-7] .....error - org.hibernate.PersistentObjectException: detached entity passed to persist: com.project.stock.business.offer.Tarif
javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.project.stock.business.offer.Tarif