I am trying to get my head around how to approach what initially seems a “simple” problem. I have UserAccounts that can have MANY Purcahses BUT business logic dictates can only have one Purchase in a PurchaseState.IDLE state (a field on the entity). A purchase is IDLE when first created. I have a repo with a method to determine if
Tag: transactions
Does TransactionAttributeType.NOT_SUPPORTED make sense for retrieving entities?
Does having TransactionAttributeType.NOT_SUPPORTED on every DB lookup method makes sense? I don’t see the point in having the entity attached if it’s not going to execute an update. Does it still end up in the cache? The only time it seems useful to use the REQUIRED transcation propagation is when an update is required: Other than that I don’t really
Cleaning up after changing the isolation level in JPA / EclipsLink EntityManager
I’m performing a transaction in JPA (EclipseLink) using a custom transaction isolation level, which I set on the underlying connection of the JPA EntityManager using this code: If I try to reset the isolation level to the old value after having committed the transaction, the underlying connection is null (entityManager.unwrap(Connection.class) returns null). I’m worried, if I just don’t reset the
How to avoid two different threads read the same rows from DB (Hibernate and Oracle 10g)
Let’s suppose I got two different threads, T1 and T2, accessing concurrently the same database and fetching data from the same table. Now on thread startup I need to fetch data from the table and store the rows into a collection, that I will then use to perform some work elsewhere. I don’t want the two threads to be able
HibernateException: Couldn’t obtain transaction-synchronized Session for current thread
I’m getting the following exception when trying to use my @Service annotated classes: The way I initialize my application is complicated so I need to provide a link to the full base code to get additional information: https://github.com/dtrunk90/webapp-base. I’m using this as a maven overlay. And here is the necessary code: Initializer (from webapp-base): Initializer (from my webapp): @Configuration (from
javax.transaction.Transactional vs org.springframework.transaction.annotation.Transactional
I don’t understand what is the actual difference between annotations javax.transaction.Transactional and org.springframework.transaction.annotation.Transactional? Is org.springframework.transaction.annotation.Transactional an extension of javax.transaction.Transactional or they have totally different meaning? When should each of them be used? Spring @Transactinal in service layer and javax in DAO? Thanks for answering. Answer Spring has defined its own Transactional annotation to make Spring bean methods transactional, years ago.
Do you need a database transaction for reading data?
When I try to read data from the database, at least using ((Session)em.getDelegate()).createCriteria() an exception is throws saying that a transaction is not present. When I add the annotation: it works fine. However, since reading will happen million of times per second to access and read data, I want to make sure that our environment is not clogged up unnecessarily.
Can you have multiple transactions within one Hibernate Session?
Can you have multiple transactions within one Hibernate Session? I’m unclear if this is an allowable desirable. In my code I have a long running thread and takes items from a Blocking Queue, depending on what is on the queue, it may need to create and save a hibernate object, or it may not need to do anything. Each item
Why does Hibernate throw org.hibernate.exception.LockAcquisitionException?
I have this method : Mapping : Person.hbm.xml Cars.hbm.xml This method works well for a single thread, and on multiple threads, gives me an error: AOP Transaction : NB : When i add Thread.sleep(5000) after update, it is ok. But this solution is not clean. Answer I have Cars -> (1 -n) places. And i have a foreign key in
JPA PessimisticLockScope.NORMAL and locking “relationships”
I am studying JPA Documentation and encountered the following lines: Entity relationships for which the locked entity contains the foreign key will also be locked, but not the state of the referenced entities (unless those entities are explicitly locked). Element collections and relationships for which the entity does not contain the foreign key (such as relationships that are mapped to