/** * Remove the id (pk) of every children and stores it to the returned list. * * @param children * @return The list of (old) ids of the children. */ protected List<Serializable> beforeSave( final Collection<? extends BaseDO<? extends Serializable>> children) { if (children == null || children.size() == 0) { return null; } final List<Serializable> idList = new ArrayList<Serializable>(children.size()); for (final BaseDO<?> child : children) { idList.add(child.getId()); child.setId(null); } return idList; }
/** * Registers all children with their old and new id. * * @param children * @param oldIdList The returned list of beforeSave(...) method. */ protected void afterSave( final Collection<? extends BaseDO<? extends Serializable>> children, final List<Serializable> oldIdList) { if (oldIdList == null) { return; } final Iterator<Serializable> oldIdListIterator = oldIdList.iterator(); final Iterator<? extends BaseDO<?>> childIterator = children.iterator(); while (oldIdListIterator.hasNext() == true) { final BaseDO<?> child = childIterator.next(); registerEntityMapping(child.getClass(), oldIdListIterator.next(), child.getId()); } }
/** * @param obj * @return */ public static <T extends Serializable> void setIdentifier(final BaseDO<T> obj, final T value) { if (Hibernate.isInitialized(obj) == true) { obj.setId(value); } else if (obj instanceof DefaultBaseDO) { ((DefaultBaseDO) obj).setId((Integer) value); } else if (obj instanceof AccessEntryDO) { ((AccessEntryDO) obj).setId((Integer) value); } else if (obj instanceof Kost2ArtDO) { ((Kost2ArtDO) obj).setId((Integer) value); } else if (obj instanceof KundeDO) { ((KundeDO) obj).setId((Integer) value); } else if (obj instanceof UserPrefEntryDO) { ((UserPrefEntryDO) obj).setId((Integer) value); } else { log.error( "Couldn't set the identifier of the given object for class: " + obj.getClass().getName()); } }
/** * Workaround for: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3502: * * @param obj * @return */ public static Serializable getIdentifier(final BaseDO<?> obj) { if (Hibernate.isInitialized(obj) == true) { return ((BaseDO<?>) obj).getId(); } else if (obj instanceof DefaultBaseDO) { return ((DefaultBaseDO) obj).getId(); } else if (obj instanceof AccessEntryDO) { return ((AccessEntryDO) obj).getId(); } else if (obj instanceof Kost2ArtDO) { return ((Kost2ArtDO) obj).getId(); } else if (obj instanceof KundeDO) { return ((KundeDO) obj).getId(); } else if (obj instanceof UserPrefEntryDO) { return ((UserPrefEntryDO) obj).getId(); } log.error( "Couldn't get the identifier of the given object (Jassist/Hibernate-Bug: HHH-3502) for class: " + obj.getClass().getName()); return null; }