Bug 434338 - Prepersist changes are lost when EntityMenager.merge() is called.
Summary: Prepersist changes are lost when EntityMenager.merge() is called.
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-07 10:44 EDT by Dan Cebotarenco CLA
Modified: 2022-06-09 10:08 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Cebotarenco CLA 2014-05-07 10:44:32 EDT
@Named
@Entity
public class TransportUnitTypeCore extends StockKeepableTypeCore implements TransportUnitType
{

  private static final long serialVersionUID = 1L;

  @ManyToMany(targetEntity = StockKeepableTypeCore.class)
  @JoinTable(name = "WMS_STOCKKEEPTYPE_WMS_TUTYPE")
  private Set<StockKeepableType> stockKeepableTypes;
  @Column(nullable = false)
  private Boolean internal = Boolean.FALSE;

  @Override
  public Set<StockKeepableType> getStockKeepableTypes()
  {
    return stockKeepableTypes;
  }

  @Override
  public void setStockKeepableTypes(Set<StockKeepableType> stockKeepableTypes)
  {
    this.stockKeepableTypes = stockKeepableTypes;
  }
}
-------------------------------------------------------

@Named
@Entity
@Table(name = "WMS_STOCKKEEPABLETYPE", uniqueConstraints =
{
  @UniqueConstraint(columnNames =
  {
    "LOGICAL_ID", "CLIENT_ID"
  })
})
@DiscriminatorColumn(name = "INTH_TYPE")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class StockKeepableTypeCore extends AbstractClientLogicalIdEntity implements StockKeepableType
{

  private static final long serialVersionUID = 1L;

  @OneToOne(optional = true, targetEntity = CubingInfoCore.class, cascade = CascadeType.ALL)
  private CubingInfo cubingInfo;

  private Double fillRate;
  //private Set<T> stockKeepables;

  private Long maxWeight;

  @Enumerated(EnumType.STRING)
  private WeightISO maxWeightISO;

  @Enumerated(EnumType.STRING)
  @Column(nullable = false)
  private StockKeepableClass stockKeepableClass;

  @ManyToMany(targetEntity = TransportUnitTypeCore.class, mappedBy = "stockKeepableTypes")
  private Set<TransportUnitType> transportUnitTypes;

  @Override
  public CubingInfo getCubingInfo()
  {
    return cubingInfo;
  }

  @Override
  public void setCubingInfo(CubingInfo cubingInfo)
  {
    this.cubingInfo = cubingInfo;
  }

  @Override
  public Double getFillRate()
  {
    return fillRate;
  }

  @Override
  public void setFillRate(Double fillRate)
  {
    this.fillRate = fillRate;
  }

//  @Override
//  @OneToMany(mappedBy = "stockKeepableType", targetEntity = AbstractStockKeepable.class)
//  public Set<T> getStockKeepables()
//  {
//    return stockKeepables;
//  }
//
//  @Override
//  public void setStockKeepables(Set<T> stockKeepables)
//  {
//    this.stockKeepables = stockKeepables;
//  }
//
  @Override
  public Long getMaxWeight()
  {
    return maxWeight;
  }

  @Override
  public void setMaxWeight(Long maxWeight)
  {
    this.maxWeight = maxWeight;
  }

  @Override
  public WeightISO getMaxWeightISO()
  {
    return maxWeightISO;
  }

  @Override
  public void setMaxWeightISO(WeightISO maxWeightISO)
  {
    this.maxWeightISO = maxWeightISO;
  }

  @Override
  public StockKeepableClass getStockKeepableClass()
  {
    return stockKeepableClass;
  }

  @Override
  public void setStockKeepableClass(StockKeepableClass stockKeepableTypeClass)
  {
    this.stockKeepableClass = stockKeepableTypeClass;
  }

  @Override
  public Set<TransportUnitType> getTransportUnitTypes()
  {
    return transportUnitTypes;
  }

  @Override
  public void setTransportUnitTypes(Set<TransportUnitType> transportUnitTypes)
  {
    this.transportUnitTypes = transportUnitTypes;
  }
}


  @Override
  public boolean getInternal()
  {
    return (internal == null ? Boolean.FALSE : internal);
  }

  @Override
  public void setInternal(Boolean internal)
  {
    this.internal = internal;
  }
}
-------------------------------------------------------
@MappedSuperclass
public abstract class AbstractClientLogicalIdEntity extends AbstractGeneratedIdEntity implements ClientLogicalIdEntity
{

  @Column(name = "LOGICAL_ID", nullable = false)
  protected String logicalId;

  /**
   * The client to which the entity belongs. If the client is <i>null</i>
   * then the entity is shared among all the clients.
   */
  @JoinColumn(name = "CLIENT_ID", nullable = false)
  @ManyToOne(fetch = FetchType.LAZY, targetEntity = ClientCore.class)
  protected Client client;

  @Override
  @XmlElement
  public String getLogicalId()
  {
    return logicalId;
  }

  @Override
  public void setLogicalId(String logicalId)
  {
    this.logicalId = logicalId;
  }

  @Override
  public Client getClient()
  {
    return client;
  }

  @Override
  public void setClient(Client client)
  {
    this.client = client;
  }

  /**
   * PrePersist listener
   */
  @PrePersist
  public void prePersistClientId()
  {
    Client seqClient = SecurityContextHolder.getContext().getClient();

    if (client == null && seqClient != null)
    {
      this.client = SecurityContextHolder.getContext().getClient();
    }
    else
    {
      this.client = SharedClientHolder.getSharedClient();
    }
  }
}

-------------------------------------------------------------------
 @Transactional(propagation = Propagation.PROPAGATION_REQUIRES_NEW)
  private void persist()
  {
    StockKeepableType skt = getStockKeepableType();
    getStockKeepableTypeDao().merge(skt);
    logger.info("User [{}] {} stockkeepabletype [{}]", new Object[]
    {
      SecurityContextHolder.getContext().getUser().getLogicalId(), this.crud == CRUD.CREATE ? "created" : "modified", skt.getLogicalId()
    });
  }

The scenario is this ... i have a StockKeepableType that actually it is a transportUnitType and i want to persist it via merge() .. the prepersist is called the client is set. In MergeManager i have the clone without clientId and after call of this method 
registerObjectForMergeCloneIntoWorkingCopy(rmiClone, shouldForceCascade());
i have the right registeredObject with cliendId ... after builder.mergeIntoObject(registeredObject, null, false, rmiClone, this, this.session, cascadeOnly, false, false);
i have registeredObject back without clientId. and this is returned..
Comment 1 Eclipse Webmaster CLA 2022-06-09 10:08:30 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink