ObjectDB ObjectDB

Problem on JPA Merge Entity.

#1

Hello,

I have a problem with the EntityManager.merge() function.

I set a property value of an entity (statement) with an other entity (newSingleConstraint).

newSingleValue is already persisted. I do this myself (no use of cascade because sometimes the newSingleValue is already in database).

The statement update don't throw exception. And when i try to reload statement the value i have set before is a null value.

I check with the Explorer, the statement has a null value on the property and the newSingleValue is present.

The entity manager don't link the newSingleValue to the statement when i update.

The statement's property is typed by a class that is a superclass of the newSingleValue.

This the chain of call that don't work:


@Component
public class ProtocolsEditorServiceImplProto implements ProtocolsEditorService {
    ....
    public void putConstraintInStatement(ConstraintForm constraint,
        String elementType, Long statementId) throws Exception {
    .....
        ergoManager.createErgoClass(newSingleConstraint);
            // if not already exist in database.
        statement.setConstraintForAttribute(elementType, newSingleConstraint);
            //set a property of statement with the newSingleConstraint
        ergoManager.updateErgoClass(statement);
    ....
    }
}

ergoManager implementation:


@Component

@Transactional
public class ErgoManagerImpl implements IErgoManager {
    public void createErgoClass(ERGOClass ergoClass)
            throws EntryAlreadyExistInDaoException, ServiceException {
        ergoDao.saveErgoClass(ergoClass);
    }

    public void updateErgoClass(ERGOClass ergoClass) throws ServiceException { 
        ergoDao.updateErgoClass(ergoClass);
    }
}

ergoDao implementation:


@Repository
public class ErgoDaoJpa implements IErgoDao {
    @PersistenceContext
    private EntityManager entityManager;

    public void saveErgoClass(ERGOClass ergoClass)
            throws EntryAlreadyExistException, DaoException {
        entityManager.persist(ergoClass);
    }

    public void updateErgoClass(ERGOClass ergoClass) throws DaoException {
        entityManager.merge(ergoClass);
    }
}

Thanks for your help.

Sorry for my bad english :)

edit
delete
#2

Please try to isolate the problem - is it an ObjectDB merge issue or Spring / JPA transaction management issue?

Maybe it is a missing @Transactional annotation on ErgoDaoJpa?

Check entityManager.getTransaction().isActive() - in which methods it is true and in which false?

In addition, verify that the same EntityManager is used.

If you can write and upload a simple test program that demonstrates the problem it could help.

 

 

ObjectDB Support
edit
delete
#3

Hi,

I think that it is an ObjectDb problem.

The same code with Spring, JPA, Hibernate and MySQL works.

 

I try to isolate to isolate the code that doesn't work and to make a little sample.

edit
delete
#4

Hi,

I just work all day on the problem reported yesterday.

I think it's really an ObjectDb merge issue. If i make other operation under the same transaction, the other operation works fine.

I haven't no Exception throwing.

I wrote a simple (more simple as possible, because i have a big hierarchy of class in entity domain) sample that highlights the problem.

 

This a little webapp (using Spring/Spring MVC, ObjectDb, JPA) project under Eclipse.

I upload the project archive.

 

The little sample is based on a web page (http://localhost:8080/ERGO_ObjectDB/)

On this web page we can found 4 links.

  • /testCreate
  • /testUpdate
  • /refresh
  • /updateAllInDao

 

  • testCreate

Create component of statement, save componenet, assign component to statement and save statement.

Works!

  • testUpdate

Retrieve statement from database, retrieve some element from database, create a new component, save new component, assign component to statement and update statement.

Works except the update.

The statement is returned to the page displayed and the new component is present but in fact the statement has not been reloaded and if we "refresh" (next item) the new component has not been attach to the statement. On the other side if we look in the ObjectDB explorer we can see that the new component has been saved but not attached to the statement.

  • refresh

Retrieve statement from database and display it.

  • updateAlInDao

Make the same operation that testUpdate, but all operations are grouped in the same function and the same transaction.

Reloaded statement before display it.

Works except update.

 

I hope to be understandable , if not the case please contact me.
 
edit
delete
#5

Thank you very much for this important bug report and the useful test application.

Please try version 2.0.5 that fixes the problem.

ObjectDB Support
edit
delete
#6

Thank you for your reactivity.

 

I try the last version monday and i give you feed back.

edit
delete
#7

Hi,

I try the version 2.0.5 and that don't fix the issue.

I try it with the test application and my full application.

In both case the bug is still there.

 

Do you check if the new version fixes the problem on the test application?

 

Thank you.

edit
delete
#8

Your test application seems to work well with 2.0.5 at least on my computer.

Please verify that you switched the server and the client (in pom.xml) to 2.0.5 and that the project was rebuilt and then redeployed with the new objectdb.jar. Which server do you use?

On create I get:

/testCreate
/testUpdate
/refresh
/updateAllInDao

  • 60
  • PrimitiveNounPhrase [code=CODE, codeSystem=CODE_SYSTEM, id=59, preferedName=PREFERED_NAME]
  • SingleValueConstraint [comparator=ERGOKeyword [id=56, preferedName==], value=TimePoint [literal=01-01-2000]]
  •  

 

On update (and similarly on updateAllInDao) I get:

/testCreate
/testUpdate
/refresh
/updateAllInDao

  • 60
  • PrimitiveNounPhrase [code=CODE, codeSystem=CODE_SYSTEM, id=59, preferedName=PREFERED_NAME]
  • SingleValueConstraint [comparator=ERGOKeyword [id=56, preferedName==], value=TimePoint [literal=01-01-2000]]
  • SingleValueConstraint [comparator=ERGOKeyword [id=56, preferedName==], value=TimePoint [literal=10-10-1900]]
ObjectDB Support
edit
delete
#9

Hi,

My apologies, in fact I did not change the version in the configuration file of maven.

That works fine.

 

Thank you.

 

edit
delete
#10

That's ok. Thanks again for your help.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.