Java Code Examples for org.hibernate.Hibernate#isInitialized()

The following examples show how to use org.hibernate.Hibernate#isInitialized() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static TaskObject getTaskObject(TaskDO taskDO)
{
  if (taskDO == null) {
    return null;
  }
  if (Hibernate.isInitialized(taskDO) == false) {
    final Integer taskId = taskDO.getId();
    taskDO = Registry.instance().getTaskTree().getTaskById(taskId);
    if (taskDO == null) {
      log.error("Oups, task with id '" + taskId + "' not found.");
      return null;
    }
  }
  final TaskObject task = new TaskObject();
  DOConverter.copyFields(task, taskDO);
  task.setParentTaskId(taskDO.getParentTaskId());
  task.setDescription(taskDO.getDescription());
  task.setReference(taskDO.getReference());
  task.setTitle(taskDO.getTitle());
  task.setShortDescription(taskDO.getShortDescription());
  task.setMaxHours(taskDO.getMaxHours());
  task.setPriority(taskDO.getPriority());
  task.setStatus(taskDO.getStatus());
  return task;
}
 
Example 2
/**
 * 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;
}
 
Example 3
private boolean isFoundInParent(
		String property, 
		Object childEntity, 
		EntityPersister persister, 
		CollectionPersister collectionPersister,
		Object potentialParent
) {
	Object collection = persister.getPropertyValue( 
			potentialParent, 
			property, 
			session.getEntityMode() 
		);
	return collection!=null && Hibernate.isInitialized(collection) &&
			collectionPersister.getCollectionType()
					.contains(collection, childEntity, session);
}
 
Example 4
Source Project: mPass   File: ValidationUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 执行校验
 * 
 * @param dto
 */
public static <T> void validate(T dto, Class<?>... groups)
		throws ParamsNotValidException {
	//处理hibernate延迟及代理对象
	if (!Hibernate.isInitialized(dto)) {
		return;
	}
	Set<ConstraintViolation<T>> result = validator
			.validate((T) Hibernate.unproxy(dto), groups);
	handleConstraintViolation(result);
	if (dto instanceof Validatable) {
		((Validatable) dto).validate(groups);
	}
}
 
Example 5
/**
 * @see org.projectforge.core.BaseDao#prepareHibernateSearch(org.projectforge.core.ExtendedBaseDO, org.projectforge.access.OperationType)
 */
@Override
protected void prepareHibernateSearch(final TimesheetDO obj, final OperationType operationType)
{
  final PFUserDO user = obj.getUser();
  if (user != null && Hibernate.isInitialized(user) == false) {
    obj.setUser(userDao.getUserGroupCache().getUser(user.getId()));
  }
  final TaskDO task = obj.getTask();
  if (task != null && Hibernate.isInitialized(task) == false) {
    obj.setTask(taskTree.getTaskById(task.getId()));
  }
}
 
Example 6
@Override
public boolean reassociateIfUninitializedProxy(Object value) throws MappingException {
	if ( !Hibernate.isInitialized( value ) ) {
		final HibernateProxy proxy = (HibernateProxy) value;
		final LazyInitializer li = proxy.getHibernateLazyInitializer();
		reassociateProxy( li, proxy );
		return true;
	}
	else {
		return false;
	}
}
 
Example 7
/**
 * Returns the collection of assigned users only if initialized. Avoids a LazyInitializationException.
 * @return
 */
@Transient
public Set<PFUserDO> getSafeAssignedUsers()
{
  if (this.assignedUsers == null || Hibernate.isInitialized(this.assignedUsers) == false) {
    return null;
  }
  return this.assignedUsers;
}
 
Example 8
public static Cost2Object getCost2Object(Kost2DO kost2DO)
{
  if (kost2DO == null) {
    return null;
  }
  if (Hibernate.isInitialized(kost2DO) == false) {
    final Integer kost2Id = kost2DO.getId();
    kost2DO = Registry.instance().getDao(Kost2Dao.class).internalGetById(kost2Id);
    if (kost2DO == null) {
      log.error("Oups, kost2 with id '" + kost2Id + "' not found.");
      return null;
    }
  }
  final Cost2Object cost2 = new Cost2Object();
  DOConverter.copyFields(cost2, kost2DO);
  cost2.setNumber(kost2DO.getFormattedNumber());
  if (kost2DO.getKost2Art() != null) {
    cost2.setType(kost2DO.getKost2Art().getName());
  }
  final ProjektDO projektDO = kost2DO.getProjekt();
  KundeDO kundeDO = null;
  if (projektDO != null) {
    cost2.setProject(projektDO.getName());
    kundeDO = projektDO.getKunde();
    if (kundeDO != null) {
      cost2.setCustomer(kundeDO.getName());
    }
  }
  return cost2;
}
 
Example 9
Source Project: unitime   File: Location.java    License: Apache License 2.0 5 votes vote down vote up
@Deprecated
  public String getHtmlHint(String preference) {
try {
	if (!Hibernate.isPropertyInitialized(this, "roomType") || !Hibernate.isInitialized(getRoomType())) {
		return LocationDAO.getInstance().get(getUniqueId()).getHtmlHintImpl(preference);
	} else {
		return getHtmlHintImpl(preference);
	}
} catch (LazyInitializationException e) {
	return LocationDAO.getInstance().get(getUniqueId()).getHtmlHintImpl(preference);
}
  }
 
Example 10
/**
 * Writes the html formatted task to the given StringBuffer.
 * @param buf
 * @param task
 * @param enableLink If true, the task has a link to the EditTask.action.
 * @param showPathAsTooltip If true, an info icon with the whole task path as tooltip will be added.
 */
public void appendFormattedTask(final RequestCycle requestCycle, final StringBuffer buf, TaskDO task, final boolean showPathAsTooltip,
    final boolean lineThroughDeletedTask)
{
  Validate.notNull(buf);
  Validate.notNull(task);
  if (showPathAsTooltip == true) {
    final String taskPath = getTaskPath(requestCycle, task.getId(), null, false);
    if (taskPath != null) {
      htmlHelper.appendImageTag(requestCycle, buf, htmlHelper.getInfoImage(), taskPath);
    }
  }
  // if (enableLink == true) {
  // htmlHelper.appendAncorStartTag(locUrlBuilder, buf,
  // WicketUtils.getBookmarkablePageUrl(TaskEditPage.class, "id", String.valueOf(task.getId())));
  // }
  if (Hibernate.isInitialized(task) == false) {
    task = taskTree.getTaskById(task.getId());
  }
  if (task.isDeleted() == true) {
    if (lineThroughDeletedTask == true) {
      buf.append("<span");
      htmlHelper.attribute(buf, "style", "text-decoration: line-through;");
      buf.append(">");
      buf.append(HtmlHelper.escapeXml(task.getTitle()));
      buf.append("</span>");
    } else {
      buf.append(HtmlHelper.escapeXml(task.getTitle())).append(" (");
      buf.append(getI18nMessage("task.deleted"));
      buf.append(")");
    }
  } else {
    buf.append(HtmlHelper.escapeXml(task.getTitle()));
  }
  // if (enableLink == true) {
  // htmlHelper.appendAncorEndTag(buf);
  // }
}
 
Example 11
public String toLoggableString(Object value, SessionFactoryImplementor factory)
		throws HibernateException {
	if ( value == null ) {
		return "null";
	}
	else if ( !Hibernate.isInitialized( value ) ) {
		return "<uninitialized>";
	}
	else {
		return renderLoggableString( value, factory );
	}
}
 
Example 12
Source Project: unitime   File: DistributionPref.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param aClass
 * @return
 */
public boolean appliesTo(Class_ aClass) {
	if (this.getDistributionObjects()==null) return false;
	Iterator it = null;
	try {
		it = getDistributionObjects().iterator();
	} catch (ObjectNotFoundException e) {
		Debug.error("Exception "+e.getMessage()+" seen for "+this);
   		new _RootDAO().getSession().refresh(this);
  			it = getDistributionObjects().iterator();
	}
	while (it.hasNext()) {
		DistributionObject dObj = (DistributionObject) it.next();
		
		//Class_ check
		//no checking whether dObj.getPrefGroup() is Class_ not needed since all PreferenceGroups have unique ids
		if (dObj.getPrefGroup().getUniqueId().equals(aClass.getUniqueId())) return true;
		
		//SchedulingSubpart check
		SchedulingSubpart ss = null;
		if (Hibernate.isInitialized(dObj.getPrefGroup())) {
			if (dObj.getPrefGroup() instanceof SchedulingSubpart) {
				ss = (SchedulingSubpart) dObj.getPrefGroup();
			}
		} else {
			//dObj.getPrefGroup() is a proxy -> try to load it
			PreferenceGroup pg = (new PreferenceGroupDAO()).get(dObj.getPrefGroup().getUniqueId());
			if (pg!=null && pg instanceof SchedulingSubpart)
				ss = (SchedulingSubpart)pg;
		}
		if (ss!=null && ss.getClasses()!=null && ss.getClasses().size()>0) {
			for (Iterator it2 = ss.getClasses().iterator();it2.hasNext();)
				if (((Class_)it2.next()).getUniqueId().equals(aClass.getUniqueId())) return true;
		}
	}
	return false;
}
 
Example 13
@Override
public Set<String> getAllowedStyles(Long id) {
    LayerDetails found = find(id);
    if ( found != null ) {
        Set<String> styles = found.getAllowedStyles();

        if ( (styles != null) && !Hibernate.isInitialized(styles) ) {
            Hibernate.initialize(styles); // fetch the props
        }

        return styles;
    } else {
        throw new IllegalArgumentException("LayerDetails not found");
    }
}
 
Example 14
public static UserObject getUserObject(PFUserDO userDO)
{
  if (userDO == null) {
    return null;
  }
  if (Hibernate.isInitialized(userDO) == false) {
    final Integer userId = userDO.getId();
    userDO = Registry.instance().getUserGroupCache().getUser(userDO.getId());
    if (userDO == null) {
      log.error("Oups, user with id '" + userId + "' not found.");
      return null;
    }
  }
  final UserObject user = new UserObject();
  DOConverter.copyFields(user, userDO);
  user.setUsername(userDO.getUsername());
  user.setFirstName(userDO.getFirstname());
  user.setLastName(userDO.getLastname());
  user.setEmail(userDO.getEmail());
  TimeZone timeZone = userDO.getTimeZoneObject();
  if (timeZone == null) {
    timeZone = Configuration.getInstance().getDefaultTimeZone();
  }
  if (timeZone != null) {
    user.setTimeZone(timeZone.getID());
  }
  Locale locale = userDO.getLocale();
  if (locale == null) {
    locale = ConfigXml.getInstance().getDefaultLocale();
  }
  if (locale == null) {
    locale = Locale.getDefault();
  }
  if (locale != null) {
    user.setLocale(locale.toString());
  }
  return user;
}
 
Example 15
public boolean hasDocument() {
	return Hibernate.isInitialized(this.document);
}
 
Example 16
public boolean hasNominalLabels() {
	return Hibernate.isInitialized(this.nominalLabels);
}
 
Example 17
public boolean hasTaskAssignments() {
	return Hibernate.isInitialized(this.taskAssignments);
}
 
Example 18
public boolean hasNominalAttribute() {
	return Hibernate.isInitialized(this.nominalAttribute);
}
 
Example 19
public boolean hasUsers() {
	return Hibernate.isInitialized(this.users);
}
 
Example 20
Source Project: EasyEE   File: CommonDAOSpringImpl.java    License: MIT License 4 votes vote down vote up
@Override
public void initialize(Object proxy) {
	if (!Hibernate.isInitialized(proxy)) {
		Hibernate.initialize(proxy);
	}
}