Changeset 6577


Ignore:
Timestamp:
Oct 24, 2014, 12:45:14 PM (7 years ago)
Author:
Nicklas Nordborg
Message:

References #1873: Deleting child biomaterial doesn't return the used quantity to the parent

This should fix the bug in the place were we spotted it and also in some other potential places were we didn't check if the object was a proxy or not.

Location:
branches/3.3-stable/src/core/net/sf/basedb/core
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-stable/src/core/net/sf/basedb/core/BioMaterialEvent.java

    r6268 r6577  
    2626import net.sf.basedb.core.query.Restrictions;
    2727import net.sf.basedb.core.query.Hql;
    28 
    2928import net.sf.basedb.core.data.BioMaterialData;
    3029import net.sf.basedb.core.data.BioMaterialEventData;
     
    719718    checkPermission(Permission.RESTRICTED_WRITE);
    720719    if (bioMaterial == null) throw new InvalidUseOfNullException("bioMaterial");
    721     BioMaterialData data = (BioMaterialData)bioMaterial.getData();
     720    BioMaterialData data = (BioMaterialData)HibernateUtil.unwrapIfProxy(getDbControl().getHibernateSession(), bioMaterial.getData());
    722721    Map<BioMaterialData, BioMaterialEventSourceData> sources = getData().getSources();
    723722    BioMaterialEventSourceData src = sources.remove(data);
     
    858857    Map<BioMaterialData, BioMaterialEventSourceData> sources = getData().getSources();
    859858    int parentId = parent == null ? 0 : parent.getId();
    860    
     859
    861860    Iterator<Map.Entry<BioMaterialData, BioMaterialEventSourceData>> it = sources.entrySet().iterator();
    862861    while (it.hasNext())
     
    865864     
    866865      BioMaterialEventSourceData src = entry.getValue();
    867       BioMaterialData bioMaterial = entry.getKey();
     866      BioMaterialData bioMaterial = (BioMaterialData)HibernateUtil.unwrapIfProxy(dc.getHibernateSession(), entry.getKey());
    868867     
    869868      if (bioMaterial.getId() != parentId)
  • branches/3.3-stable/src/core/net/sf/basedb/core/BioMaterialEventSource.java

    r5963 r6577  
    2525import java.util.Set;
    2626
     27import net.sf.basedb.core.data.BioMaterialData;
    2728import net.sf.basedb.core.data.BioMaterialEventSourceData;
    2829import net.sf.basedb.core.data.MeasuredBioMaterialData;
     
    167168  {
    168169    checkPermission(Permission.RESTRICTED_WRITE);
    169     if (data.getBioMaterial() instanceof MeasuredBioMaterialData)
    170     {
    171       MeasuredBioMaterialData mbData = (MeasuredBioMaterialData)data.getBioMaterial();
     170    BioMaterialData bm = (BioMaterialData)HibernateUtil.unwrapIfProxy(dc.getHibernateSession(), data.getBioMaterial());
     171    if (bm instanceof MeasuredBioMaterialData)
     172    {
     173      MeasuredBioMaterialData mbData = (MeasuredBioMaterialData)bm;
    172174      Float delta = 0.0f;
    173175      if (data.getUsedQuantity() != null)
  • branches/3.3-stable/src/core/net/sf/basedb/core/HibernateUtil.java

    r6444 r6577  
    4343import net.sf.basedb.core.hibernate.ExecuteUpdateWork;
    4444import net.sf.basedb.core.hibernate.SchemaGenerator;
     45import net.sf.basedb.core.hibernate.SessionWrapper;
    4546import net.sf.basedb.core.hibernate.TypeWrapper;
    4647import net.sf.basedb.core.hibernate.JdbcWork;
     
    7172import org.jdom.Element;
    7273import org.jdom.output.DOMOutputter;
    73 
    7474import org.hibernate.Hibernate;
    7575import org.hibernate.Interceptor;
     
    14181418      throw new BaseException(ex);
    14191419    }   
     1420  }
     1421 
     1422  /**
     1423    If the given data object is a proxy, load the real data object instead.
     1424    @since 3.3.3
     1425  */
     1426  static BasicData unwrapIfProxy(Session session, BasicData data)
     1427  {
     1428    if (data instanceof org.hibernate.proxy.HibernateProxy)
     1429    {
     1430      org.hibernate.proxy.HibernateProxy proxy = (org.hibernate.proxy.HibernateProxy)data;
     1431      org.hibernate.proxy.LazyInitializer li = proxy.getHibernateLazyInitializer();
     1432      if (li.isUninitialized())
     1433      {
     1434        if (session instanceof SessionWrapper)
     1435        {
     1436          session = ((SessionWrapper)session).getParentSession();
     1437        }
     1438        li.setSession((org.hibernate.impl.SessionImpl)session);
     1439      }
     1440      data = (BasicData)li.getImplementation();
     1441    }
     1442
     1443    return data;
    14201444  }
    14211445 
Note: See TracChangeset for help on using the changeset viewer.