in Education by
As far as I've experienced JPA/hibernate will return entities that either exists at the database or have been persisted during the transaction and then flushed to the database. I'd like to be able for certain queries to ask Hibernate for the database as-is without taking into consideration any active transaction, any entity flushed, etc.. In these certain cases I only want to read what it is committed. Setting the flushmode to 'COMMIT' it is not what I'm looking for as I only want to read DB as is -skipping flushed entities- in certain cases like calling this 'findCommittedEntities' method. A simple code that shows what I'm looking for: @Transactional() public void mySampler(){ Entity ent=new Entity(); entityManager.persist(ent) /*Here JPA/Hibernate configured with flushmode AUTO will flush the *persisted entity to db. That's Perfect! */ List entities=service.findEntities() //So this list should be of size 1 assuming we started with an empty DB of course! System.out.println(entities.size()) //But I also would like to be able to read the DB as is: List entitiesCommited=service.findCommittedEntities(...) //This should be of size 0 as transaction is not commited yet System.out.println(entitiesCommited.size()) } So What should I do to accomplish that? Or is it not possible at all? As for environment I'm working with OSGi and Aries JPA/JTA but I think this shouldn't matter here JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
To answer my question as I already found a solution and looking forward might be useful for someone else: The implementation of the method: List entitiesCommited=service.findCommittedEntities(...) should be something like: //We require a new transaction @Transactional(value = TxType.REQUIRES_NEW) public Entity findCommitedEntities(..){ /*This is important to create a new one. Because if we use the one we *are using in 'mySampler()' we would be running the query in the scope *of the other transaction and not the new one*/ EntityManager newTxEm=emf.createEntityManager() //We join if it is not already to the new transaction newTxEm.joinTrasaction(); [...] // we execute whatever named query that gets all entities [...] return entities; }

Related questions

0 votes
    42 0.38) Symbols helps to avoid unnecessary displayed on the stage. Mark only one oval. a) expansion b) curent ... ) d) library palette Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
0 votes
    I'm trying to fetch some data from the REST API of HP Alm. It works pretty well with a small ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    Which model is used when there contains relationships between entities? (1)External Model (2)All the Options (3)Reference Model (4)Embedded Model...
asked May 23, 2021 in Technology by JackTerrance
0 votes
    I am trying to simulate the look and feel of a Firefox disabled text input: textarea and input text. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 25, 2022 in Education by JackTerrance
0 votes
    I am trying to simulate the look and feel of a Firefox disabled text input: textarea and input text. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
0 votes
    How do you open a read-only Shared Object Repository in QTP?...
asked Oct 19, 2020 in Technology by JackTerrance
0 votes
    If an transaction is performed in a database and committed, the changes are taken to the previous state ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    The ___________ policy, allows the system to write modified blocks to disk even if the transactions that ... Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    ___________ refers to the ability of the system to recover committed transaction updates if either the system ... in chapter Query Processing Techniques of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    If a transaction does not modify the database until it has committed, it is said to use the ___________ ... from Recovery topic in division Recovery System of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    I'm using an abstract superclass for some React components that share methods and some (but not all) props ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I'm using an abstract superclass for some React components that share methods and some (but not all) props ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
...