3091 words

Problem on JPA Merge Entity.

#1
2011-02-03 16:57

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 :)

guli
guli's picture
Joined on 2011-02-02
User Post #1
#2
2011-02-03 18:24

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #121
#3
2011-02-04 09:38

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.

guli
guli's picture
Joined on 2011-02-02
User Post #2
#4
2011-02-04 16:58

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.

guli
guli's picture
Joined on 2011-02-02
User Post #3
#5
2011-02-05 22:17

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #122
#6
2011-02-05 23:24

Thank you for your reactivity.

 

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

guli
guli's picture
Joined on 2011-02-02
User Post #4
#7
2011-02-07 10:28

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.

guli
guli's picture
Joined on 2011-02-02
User Post #5
#8
2011-02-07 13:55

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #126
#9
2011-02-07 16:02

Hi,

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

That works fine.

 

Thank you.

 

guli
guli's picture
Joined on 2011-02-02
User Post #6
#10
2011-02-07 16:42

That's ok. Thanks again for your help.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #126

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel