Example usage for org.hibernate Session persist

List of usage examples for org.hibernate Session persist

Introduction

In this page you can find the example usage for org.hibernate Session persist.

Prototype

void persist(Object object);

Source Link

Document

Make a transient instance persistent.

Usage

From source file:itensil.repository.hibernate.RepositoryEntity.java

License:Open Source License

/**
 *
 * @param uri//from  w w  w . j a  va 2s . c om
 * @param isCollection
 * @param owner
 * @return node object
 * @throws AccessDeniedException
 * @throws NotFoundException
 * @throws DuplicateException
 * @throws LockException
 */
public MutableRepositoryNode createNode(String uri, boolean isCollection, User owner)
        throws AccessDeniedException, NotFoundException, DuplicateException, LockException {

    User caller = SecurityAssociation.getUser();
    authorizedCheck(caller);
    Session session = HibernateUtil.getSession();

    uri = localizeUri(uri);

    // check parent elegability
    String parentUri = UriHelper.getParent(uri);
    if (parentUri.equals(uri)) {
        throw new DuplicateException(parentUri);
    }
    Query qry = session.getNamedQuery("Repo.getNodeByUri");
    qry.setEntity("repo", this);
    qry.setString("uri", parentUri);
    NodeEntity parentNode = (NodeEntity) qry.uniqueResult();
    if (parentNode == null) {
        if (!existingAncestorBlock(caller, parentUri)) {
            throw new NotFoundException(absoluteUri(parentUri));
        } else {
            throw new AccessDeniedException(absoluteUri(parentUri), "read");
        }
    }
    if (!parentNode.isCollection()) {
        throw new AccessDeniedException(absoluteUri(parentUri), "collection");
    }
    if (!hasPermission(caller, parentNode, DefaultNodePermission.CREATE)) {
        throw new AccessDeniedException(absoluteUri(parentUri), "create");
    }

    // check for duplicates
    qry.setString("uri", uri);
    Iterator itr = qry.iterate();
    if (itr.hasNext()) {
        throw new DuplicateException(uri);
    }

    // parent locked?
    checkLocked(caller, parentNode);

    NodeEntity node = new NodeEntity();
    node.initNew();
    node.setOwner(owner);
    node.setParentNode(parentNode);
    node.setCollection(isCollection);
    node.setLocalUri(uri);
    node.setRepoEntity(this);
    node.setCreateTime(new Date());
    session.persist(node);

    Set<NodeEntity> parKids = parentNode.getChildEntities();
    if (Hibernate.isInitialized(parKids)) {
        parKids.add(node);
    }

    return node;
}

From source file:itensil.security.hibernate.UserSpaceEntity.java

License:Open Source License

public User createUser(String userName, String simpleName, String password, Set<String> roles, Locale locale,
        TimeZone timezone) throws UserSpaceException {

    HashSet<String> inviteRoles = new HashSet<String>(ADMIN_ROLE);
    inviteRoles.add("inviter");

    checkAccess(inviteRoles);/*  www.  j a va 2s  .c  om*/

    // check for duplicates
    Session session = HibernateUtil.getSession();
    Query qry = session.getNamedQuery("USpace.anyUserByName");
    qry.setString("name", userName);
    UserEntity userEnt = (UserEntity) qry.uniqueResult();
    if (userEnt != null) {
        if (userEnt.getUserSpaceUsers().containsKey(this))
            throw new DuplicatePrincipalException("Duplicate user");
    } else {

        userEnt = new UserEntity();
        userEnt.initNew();
        userEnt.setUserName(userName);
        userEnt.setSimpleName(simpleName);
        userEnt.setLocale(locale);
        userEnt.setTimeZone(timezone);
        userEnt.setCreateTime(new Date());
        userEnt.setPasswordHash(SignOnHB.hashPassword(password));
        session.persist(userEnt);
    }

    USpaceUserEntity uus = new USpaceUserEntity();
    uus.setUserSpaceEntity(this);
    uus.setUserEntity(userEnt);
    uus.setRoleStr(StringHelper.stringFromSet(roles));
    uus.setCreateTime(new Date());
    session.persist(uus);

    if (userEnt.getUSpaceUser() == null) {
        userEnt.setUSpaceUser(uus);
    }

    userEnt.getUserSpaceUsers().put(this, uus);

    Map<UserEntity, USpaceUserEntity> uspus = getUserSpaceUsers();
    if (Hibernate.isInitialized(uspus)) {
        uspus.put(userEnt, uus);
    }
    userEnt.setActiveUserSpace(this);

    return userEnt;
}

From source file:itensil.security.hibernate.UserSpaceEntity.java

License:Open Source License

public Group createGroup(String groupName, String simpleName) throws UserSpaceException {

    HashSet<String> addGrpRoles = new HashSet<String>(ADMIN_ROLE);
    // special cases
    if (DEF_GROUPS.contains(simpleName)) {
        addGrpRoles.add("inviter");
    }//w  w  w . ja va2  s.c  om
    checkAccess(addGrpRoles);

    // check for duplicates
    Session session = HibernateUtil.getSession();
    Query qry = session.getNamedQuery("USpace.groupByName");
    qry.setString("name", groupName);
    qry.setEntity("uspace", this);
    if (qry.uniqueResult() != null) {
        throw new DuplicatePrincipalException("Duplicate group name");
    }

    GroupEntity groupEnt = new GroupEntity();
    groupEnt.initNew();
    groupEnt.setGroupName(groupName);
    groupEnt.setSimpleName(simpleName);
    groupEnt.setUserSpaceEntity(this);

    session.persist(groupEnt);
    Set<GroupEntity> groups = getGroupEntities();
    if (Hibernate.isInitialized(groups)) {
        groups.add(groupEnt);
    }
    return groupEnt;
}

From source file:itensil.workflow.activities.signals.WFSignalManagerJunit.java

License:Open Source License

@SuppressWarnings("unchecked")
public void testPersistSignal1_NoExistingTransaction() throws Exception {

    Session session = HibernateUtil.getSession();
    String usr1Id = "junitUsr1";
    String usr2Id = "junitUsr2";
    String flowId = "flow1";

    HibernateUtil.beginTransaction();//from w w w  .  jav  a2 s. co  m
    Object del = session.get(FlowState.class, flowId);
    if (del != null)
        session.delete((FlowState) del);
    HibernateUtil.commitTransaction();

    HibernateUtil.beginTransaction();
    FlowState fState = new FlowState();
    fState.setId(flowId);
    fState.setActive(true);

    session.saveOrUpdate(fState);

    Activity item1 = new Activity(idGen.createID().toString());
    item1.setFlow(fState);
    //item1.setId(normSess.getIdentifier());
    item1.setName("Activity One");

    item1.setSubmitId(usr2Id);
    ActivityStepState state = new ActivityStepState();
    state.setAssignId(usr1Id);
    state.setActivity(item1);
    state.setStepId("My Step");
    item1.getStates().put(state.getStepId(), state);

    Activity subItem1 = new Activity(idGen.createID().toString());
    subItem1.setFlow(fState);
    subItem1.setName("Sub Activity One");

    subItem1.setSubmitId(usr2Id);
    subItem1.setParent(item1);
    ActivityStepState state2 = new ActivityStepState();
    state2.setAssignId(usr1Id);
    state2.setActivity(subItem1);
    state2.setStepId("My Other Step");
    subItem1.getStates().put(state2.getStepId(), state2);

    session.persist(item1);
    session.persist(subItem1);
    session.persist(state);
    session.persist(state2);

    HibernateUtil.commitTransaction();

    SignalImpl sig = new AlertSignalImpl();
    sig.setActivity(item1);
    sig.setStepId("My Other Step");
    sig.setAssignId(state.getAssignId());
    sig.setMailed(SignalManager.SIGNAL_STATUS_ACTIVE_PENDING);
    sig.setTimeStamp(new Date());
    sig.setRole("role1");

    assertNull("signal id is not null", sig.getId());

    SignalManager.saveOrUpdateSignal(sig);

    assertNotNull("signal id is null", sig.getId());

    SignalManager.deleteSignal(sig);
}

From source file:itensil.workflow.activities.signals.WFSignalManagerJunit.java

License:Open Source License

@SuppressWarnings("unchecked")
public void testPersistSignal1_ExistingTransaction() throws Exception {

    Session session = HibernateUtil.getSession();
    String usr1Id = "junitUsr1";
    String usr2Id = "junitUsr2";
    String flowId = "flow1";

    HibernateUtil.beginTransaction();/* w  ww.  j  a  v a  2s  .  com*/
    Object del = session.get(FlowState.class, flowId);
    if (del != null)
        session.delete((FlowState) del);
    HibernateUtil.commitTransaction();

    HibernateUtil.beginTransaction();
    FlowState fState = new FlowState();
    fState.setId(flowId);
    fState.setActive(true);

    session.saveOrUpdate(fState);

    Activity item1 = new Activity(idGen.createID().toString());
    item1.setFlow(fState);
    item1.setName("Activity One");

    item1.setSubmitId(usr2Id);
    ActivityStepState state = new ActivityStepState();
    state.setAssignId(usr1Id);
    state.setActivity(item1);
    state.setStepId("My Step");
    item1.getStates().put(state.getStepId(), state);

    Activity subItem1 = new Activity(idGen.createID().toString());
    subItem1.setFlow(fState);
    subItem1.setName("Sub Activity One");

    subItem1.setSubmitId(usr2Id);
    subItem1.setParent(item1);
    ActivityStepState state2 = new ActivityStepState();
    state2.setAssignId(usr1Id);
    state2.setActivity(subItem1);
    state2.setStepId("My Other Step");
    subItem1.getStates().put(state2.getStepId(), state2);

    //item1.getChildren().add(subItem1);
    session.persist(item1);
    session.persist(subItem1);
    session.persist(state);
    session.persist(state2);

    //normSess.persist(state);

    HibernateUtil.commitTransaction();

    HibernateUtil.beginTransaction();

    SignalImpl sig = new AlertSignalImpl();
    sig.setActivity(item1);
    sig.setStepId("My Other Step");
    sig.setAssignId(state.getAssignId());
    sig.setMailed(SignalManager.SIGNAL_STATUS_ACTIVE_PENDING);
    sig.setTimeStamp(new Date());
    sig.setRole("role1");

    assertNull("signal id is not null", sig.getId());

    SignalManager.saveOrUpdateSignal(sig);

    HibernateUtil.commitTransaction();

    assertNotNull("signal id is null", sig.getId());

    SignalManager.deleteSignal(sig);

}

From source file:itensil.workflow.activities.signals.WFSignalManagerJunit.java

License:Open Source License

@SuppressWarnings("unchecked")
public void testPendingAlertCountGetAlerts() throws Exception {

    Session session = HibernateUtil.getSession();

    String flowId = "flow1";

    HibernateUtil.beginTransaction();/*from   ww w  .ja va 2  s. co m*/
    Object del = session.get(FlowState.class, flowId);
    if (del != null)
        session.delete((FlowState) del);
    HibernateUtil.commitTransaction();

    SecurityAssociation.setUser(SysAdmin.getUser());

    // create user  id for test
    HibernateUtil.beginTransaction();
    long idMod = System.currentTimeMillis();
    String name = "junit" + idMod;
    String name2 = "junit2" + idMod;
    UserSpaceEntity uspace = UserSpaceEntity.createUserSpace(name);
    UserEntity user = (UserEntity) uspace.createUser(userName, "junit", "pass", role, Locale.getDefault(),
            TimeZone.getDefault());
    HibernateUtil.commitTransaction();

    // build alert for user id
    String assignedUserId = user.getUserId();
    //String usr1Id = "junitUsr1";
    String submitId = "junitUsr2";

    HibernateUtil.beginTransaction();
    FlowState fState = new FlowState();
    fState.setId(flowId);
    fState.setActive(true);

    session.saveOrUpdate(fState);

    Activity item1 = new Activity(idGen.createID().toString());
    item1.setFlow(fState);
    //item1.setId(normSess.getIdentifier());
    item1.setName("Activity One");

    item1.setSubmitId(submitId);
    ActivityStepState state = new ActivityStepState();
    state.setAssignId(assignedUserId);
    state.setActivity(item1);
    state.setStepId("My Step");
    item1.getStates().put(state.getStepId(), state);

    Activity subItem1 = new Activity(idGen.createID().toString());
    subItem1.setFlow(fState);
    subItem1.setName("Sub Activity One");

    subItem1.setSubmitId(submitId);
    subItem1.setParent(item1);
    ActivityStepState state2 = new ActivityStepState();
    state2.setAssignId(assignedUserId);
    state2.setActivity(subItem1);
    state2.setStepId("My Other Step");
    subItem1.getStates().put(state2.getStepId(), state2);

    //item1.getChildren().add(subItem1);
    session.persist(item1);
    session.persist(subItem1);
    session.persist(state);
    session.persist(state2);

    //normSess.persist(state);

    HibernateUtil.commitTransaction();

    SignalImpl sig = new AlertSignalImpl();
    sig.setActivity(item1);
    sig.setStepId("My Other Step");
    sig.setAssignId(state.getAssignId());
    sig.setMailed(SignalManager.SIGNAL_STATUS_ACTIVE_PENDING);
    sig.setTimeStamp(new Date());
    sig.setRole("role1");

    SignalManager.saveOrUpdateSignal(sig);
    String sigId = sig.getId();

    int count = SignalManager.pendingAlertCount(user);

    assertEquals(1, count);

    sig = null;

    List<SignalImpl> sigList = SignalManager.getAlerts(user);

    assertEquals("number alert for user error", 1, sigList.size());

    assertEquals("signal id retrieved does not match", sigId, sigList.get(0).getId());

    sig = new AlertSignalImpl();
    sig.setActivity(item1);
    sig.setStepId("My Other Step");
    sig.setAssignId(state.getAssignId());
    sig.setMailed(SignalManager.SIGNAL_STATUS_ACTIVE_PENDING);
    sig.setTimeStamp(new Date());
    sig.setRole("role1");

    SignalManager.saveOrUpdateSignal(sig);

    sigList = SignalManager.getAlerts(user);

    assertEquals(2, sigList.size());

    assertEquals("signal id retrieved does not match", sigId, sigList.get(0).getId());
    assertEquals("signal id retrieved does not match", sig.getId(), sigList.get(1).getId());

}

From source file:itensil.workflow.activities.signals.WFSignalManagerJunit.java

License:Open Source License

@SuppressWarnings("unchecked")
public void testGetSignalStatus() throws Exception {

    Session session = HibernateUtil.getSession();

    String flowId = "flow1";

    HibernateUtil.beginTransaction();/*from   w w  w  .  ja  v  a  2 s .c o  m*/
    Object del = session.get(FlowState.class, flowId);
    if (del != null)
        session.delete((FlowState) del);
    HibernateUtil.commitTransaction();

    SecurityAssociation.setUser(SysAdmin.getUser());

    // create user  id for test
    HibernateUtil.beginTransaction();
    long idMod = System.currentTimeMillis();
    String name = "junit" + idMod;
    String name2 = "junit2" + idMod;
    UserSpaceEntity uspace = UserSpaceEntity.createUserSpace(name);
    UserEntity user = (UserEntity) uspace.createUser(userName, "junit", "pass", role, Locale.getDefault(),
            TimeZone.getDefault());
    HibernateUtil.commitTransaction();

    // build alert for user id
    String assignedUserId = user.getUserId();
    //String usr1Id = "junitUsr1";
    String submitId = "junitUsr2";

    HibernateUtil.beginTransaction();
    FlowState fState = new FlowState();
    fState.setId(flowId);
    fState.setActive(true);

    session.saveOrUpdate(fState);

    Activity item1 = new Activity(idGen.createID().toString());
    item1.setFlow(fState);
    //item1.setId(normSess.getIdentifier());
    item1.setName("Activity One");

    item1.setSubmitId(submitId);
    ActivityStepState state = new ActivityStepState();
    state.setAssignId(assignedUserId);
    state.setActivity(item1);
    state.setStepId("My Step");
    item1.getStates().put(state.getStepId(), state);

    Activity subItem1 = new Activity(idGen.createID().toString());
    subItem1.setFlow(fState);
    subItem1.setName("Sub Activity One");

    subItem1.setSubmitId(submitId);
    subItem1.setParent(item1);
    ActivityStepState state2 = new ActivityStepState();
    state2.setAssignId(assignedUserId);
    state2.setActivity(subItem1);
    state2.setStepId("My Other Step");
    subItem1.getStates().put(state2.getStepId(), state2);

    //item1.getChildren().add(subItem1);
    session.persist(item1);
    session.persist(subItem1);
    session.persist(state);
    session.persist(state2);

    //normSess.persist(state);

    HibernateUtil.commitTransaction();

    SignalImpl sig = new AlertSignalImpl();
    sig.setActivity(item1);
    sig.setStepId("My Other Step");
    sig.setAssignId(state.getAssignId());
    sig.setMailed(SignalManager.SIGNAL_STATUS_ACTIVE_PENDING);
    sig.setTimeStamp(new Date());
    sig.setRole("role1");

    SignalManager.saveOrUpdateSignal(sig);

    long sigMask = SignalManager.getSignalStatus(user);

    assertEquals("Activity Alert signal mask not properly set", SignalUtil.SIGNAL_ACTIVE_ALERT_MASK,
            sigMask & SignalUtil.SIGNAL_ACTIVE_ALERT_MASK);

}

From source file:itensil.workflow.activities.signals.WFSignalManagerJunit.java

License:Open Source License

@SuppressWarnings("unchecked")
public void testMarkAlertAsRead() throws Exception {

    Session session = HibernateUtil.getSession();

    String flowId = "flow1";

    HibernateUtil.beginTransaction();//from  w  w  w  .  j  av a2 s .  c  om
    Object del = session.get(FlowState.class, flowId);
    if (del != null)
        session.delete((FlowState) del);
    HibernateUtil.commitTransaction();

    SecurityAssociation.setUser(SysAdmin.getUser());

    // create user  id for test
    HibernateUtil.beginTransaction();
    long idMod = System.currentTimeMillis();
    String name = "junit" + idMod;
    String name2 = "junit2" + idMod;
    UserSpaceEntity uspace = UserSpaceEntity.createUserSpace(name);
    UserEntity user = (UserEntity) uspace.createUser(userName, "junit", "pass", role, Locale.getDefault(),
            TimeZone.getDefault());
    HibernateUtil.commitTransaction();

    // build alert for user id
    String assignedUserId = user.getUserId();
    //String usr1Id = "junitUsr1";
    String submitId = "junitUsr2";

    HibernateUtil.beginTransaction();
    FlowState fState = new FlowState();
    fState.setId(flowId);
    fState.setActive(true);

    session.saveOrUpdate(fState);

    Activity item1 = new Activity(idGen.createID().toString());
    item1.setFlow(fState);
    //item1.setId(normSess.getIdentifier());
    item1.setName("Activity One");

    item1.setSubmitId(submitId);
    ActivityStepState state = new ActivityStepState();
    state.setAssignId(assignedUserId);
    state.setActivity(item1);
    state.setStepId("My Step");
    item1.getStates().put(state.getStepId(), state);

    Activity subItem1 = new Activity(idGen.createID().toString());
    subItem1.setFlow(fState);
    subItem1.setName("Sub Activity One");

    subItem1.setSubmitId(submitId);
    subItem1.setParent(item1);
    ActivityStepState state2 = new ActivityStepState();
    state2.setAssignId(assignedUserId);
    state2.setActivity(subItem1);
    state2.setStepId("My Other Step");
    subItem1.getStates().put(state2.getStepId(), state2);

    //item1.getChildren().add(subItem1);
    session.persist(item1);
    session.persist(subItem1);
    session.persist(state);
    session.persist(state2);

    //normSess.persist(state);

    HibernateUtil.commitTransaction();

    SignalImpl sig = new AlertSignalImpl();
    sig.setActivity(item1);
    sig.setStepId("My Other Step");
    sig.setAssignId(state.getAssignId());
    sig.setMailed(SignalManager.SIGNAL_STATUS_ACTIVE_PENDING);
    sig.setTimeStamp(new Date());
    sig.setRole("role1");

    SignalManager.saveOrUpdateSignal(sig);

    sig = null;

    List<SignalImpl> sigList = SignalManager.getAlerts(user);

    assertEquals("number alert for user error", 1, sigList.size());
    assertEquals("alert read status error", false, sigList.get(0).read);

    SignalManager.markAlertAsRead(sigList.get(0).getId());

    sig = null;

    // get alert after update
    sigList = SignalManager.getAlerts(user);

    assertEquals("number alert for user error", 1, sigList.size());
    assertEquals("alert read status error", true, sigList.get(0).read);

}

From source file:itensil.workflow.activities.UserActivities.java

License:Open Source License

/**
 * Send an activity from one process to another
 * // ww w  .j  a  v a2s .c  o m
 * @param activityEnt
 * @param flowUri
 * @param mastUri when not empty/null, this will force process creation and uniquify the flowUri
 * @throws AccessDeniedException 
 * @throws NotFoundException
 * @throws LockException 
 * @throws DuplicateException 
 * @throws SAXException 
 * @throws IOException 
 * @throws StateException 
 * @throws EvalException 
 * @throws ActivityStepException 
 * @throws RunException 
 */
public Activity sendToFlow(Activity activityEnt, String flowUri, String mastUri)
        throws NotFoundException, AccessDeniedException, DuplicateException, LockException, IOException,
        SAXException, RunException, ActivityStepException, EvalException, StateException {

    // check if same process
    boolean create = !Check.isEmpty(mastUri);
    try {
        if (!create && activityEnt.getFlow().getNode().getUri().equals(flowUri))
            return activityEnt;
    } catch (NotFoundException nfe) {
        // eat it
    }

    MutableRepositoryNode flowNode;

    FlowState flowState = null;
    Session sess = getSession();

    if (create) {
        flowUri = RepositoryHelper.getAvailableUri(flowUri);
        MutableRepositoryNode mastNode = RepositoryHelper.getNode(mastUri, false);

        // copy master-flow
        // in the future this may do `crazy' inheritance stuff
        flowNode = (MutableRepositoryNode) mastNode.copy(flowUri, true);
    } else {
        flowNode = RepositoryHelper.getNode(flowUri, false);
        flowState = (FlowState) sess.get(FlowState.class, flowNode.getNodeId());

    }

    FlowModel flowMod = new FlowModel();
    FlowSAXHandler hand = new FlowSAXHandler(flowMod);
    hand.parse(RepositoryHelper.loadContent(UriHelper.absoluteUri(flowUri, "chart.flow")));

    // verify flowstate
    if (flowState == null) {
        flowState = new FlowState(flowNode.getNodeId());
        flowState.setActive(true);
        CustValDataContentListener.modelStateSync(flowState, flowMod);
        sess.persist(flowState);
    }
    MutableRepositoryNode activityNode;
    boolean needReId = false;
    try {
        activityNode = (MutableRepositoryNode) activityEnt.getNode();
    } catch (NotFoundException nfe) {
        activityNode = null;
        needReId = true;
    }

    activityNode = createActivityFolder(flowUri, activityEnt.getName(), activityNode);

    activityEnt.setName(UriHelper.name(activityNode.getUri()));
    activityEnt.setFlow(flowState);

    // reset the states

    for (ActivityStepState actState : activityEnt.getStates().values()) {
        sess.delete(actState);
    }
    activityEnt.getStates().clear();

    activityEnt.setVariationId(null);

    // TODO - decide to clear plans?

    if (needReId) {
        activityEnt = activityEnt.changeActivityId(activityNode.getNodeId());
    }

    /*
    * some kind of bug here, I suspect hibernate...
    * need to flush to ensure delete
    */
    getSession().flush();

    // start the activity in the process
    ActivityStateStore store = new ActivityStateStore(flowState);
    Runner<Activity, String> run = new Runner<Activity, String>(flowMod, store, store,
            new XPathConditionEval<String>(flowMod), new WFActivityStepInvoker<String>());

    run.handleEvent(new FlowEvent<Activity, String>(activityEnt, run.startToken(null, activityEnt)));

    return activityEnt;
}

From source file:itensil.workflow.activities.WFItemJunit.java

License:Open Source License

@SuppressWarnings("unchecked")
public void testUserItem() throws Exception {
    Session normSess = HibernateUtil.getSession();
    String usr1Id = "junitUsr1";
    String usr2Id = "junitUsr2";
    String flowId = "flow1";

    HibernateUtil.beginTransaction();//from w  w w  . j a v  a  2  s. c  om
    FlowState fState = new FlowState();
    fState.setId(flowId);
    fState.setActive(true);

    normSess.saveOrUpdate(fState);

    Activity item1 = new Activity(idGen.createID().toString());
    item1.setFlow(fState);
    //item1.setId(normSess.getIdentifier());
    item1.setName("Activity One");

    item1.setSubmitId(usr2Id);
    ActivityStepState state = new ActivityStepState();
    state.setAssignId(usr1Id);
    state.setActivity(item1);
    state.setStepId("My Step");
    item1.getStates().put(state.getStepId(), state);

    Activity subItem1 = new Activity(idGen.createID().toString());
    subItem1.setFlow(fState);
    subItem1.setName("Sub Activity One");

    subItem1.setSubmitId(usr2Id);
    subItem1.setParent(item1);
    ActivityStepState state2 = new ActivityStepState();
    state2.setAssignId(usr1Id);
    state2.setActivity(subItem1);
    state2.setStepId("My Other Step");
    subItem1.getStates().put(state2.getStepId(), state2);

    //item1.getChildren().add(subItem1);
    normSess.persist(item1);
    normSess.persist(subItem1);
    normSess.persist(state);
    normSess.persist(state2);

    //normSess.persist(state);

    HibernateUtil.commitTransaction();

    HibernateUtil.beginTransaction();
    normSess = HibernateUtil.getSession();
    normSess.refresh(item1);
    assertEquals(1, item1.getChildren().size());
    HibernateUtil.commitTransaction();

    HibernateUtil.beginTransaction();
    normSess = HibernateUtil.getSession();

    Activity act1 = (Activity) normSess.get(Activity.class, item1.getId());
    System.out.println(ActivityXML.display(act1));

    act1 = (Activity) normSess.get(Activity.class, subItem1.getId());
    System.out.println(ActivityXML.display(act1));

    System.out.println("--getAssignItems--");

    UserActivities usrItms = new UserActivities(new DefaultUser(usr1Id), normSess);
    List<Activity> asgnElems = usrItms.getAssignActivities(0, false);
    for (Activity aEl : asgnElems) {
        System.out.println(ActivityXML.display(aEl));
    }

    System.out.println("--getSubmitItems--");
    usrItms = new UserActivities(new DefaultUser(usr2Id), normSess);
    List<Activity> subtElems = usrItms.getSubmitActivities(0, false);
    for (Activity sEl : subtElems) {
        System.out.println(ActivityXML.display(sEl));
    }

    HibernateUtil.closeSession();
}