AnsweredAssumed Answered

Create/Reuse a node

Question asked by swithun on Oct 14, 2010
Latest reply on Oct 27, 2010 by swithun
I'm having difficulty writing to the content of a node, if the node already exists. I have an action which tries create a node and write some content to it based on the node on which the action is run. This is fine if a node with the given name doesn't already exist. But if such a node already exists, because the same action has already been run on the original node, then I run into problems.

The code is a bit like this:

try
  {
    fileRef = fileFolderService.create(dirRef, fileName, PROP_QNAME_CONTENT).getNodeRef();
  }
catch (FileExistsException ffe)
  {
    // what should go here?
  }
ContentWriter writer = contentService.getWriter(fileRef, ContentModel.PROP_CONTENT, true);
writer.putContent(output);

I've tried to get a nodeRef for the node in various ways, and tried deleting it and then creating it again. Nothing gives me a usable nodeRef that I can use with getWriter. I always get a very long and unhelpful stack trace:

09:41:43,619 User:admin ERROR [org.hibernate.AssertionFailure] an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: null id in org.alfresco.repo.domain.hibernate.ChildAssocImpl entry (don't flush the Session after an exception occurs)
        at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:55)
        at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:164)
        at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:120)
        at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
        at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
        at org.alfresco.repo.domain.hibernate.DirtySessionMethodInterceptor.flushSession(DirtySessionMethodInterceptor.java:336)
        at org.alfresco.repo.node.db.hibernate.HibernateNodeDaoServiceImpl$SessionFlusher.doInHibernate(HibernateNodeDaoServiceImpl.java:5431)
        at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
        at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339)
        at org.alfresco.repo.node.db.hibernate.HibernateNodeDaoServiceImpl.addNodePropertyImpl(HibernateNodeDaoServiceImpl.java:1463)
        at org.alfresco.repo.node.db.hibernate.HibernateNodeDaoServiceImpl.addNodeProperty(HibernateNodeDaoServiceImpl.java:1510)

Has anyone faced and solved a similar problem?

Outcomes