Spring @Transactional(Propagation.NEVER) should create Hibernate session?

The behavior is correct – Hibernate will always create a session (how else would you expect it to perform any operation?), and by loading the entity you have associated it with that session. Since withoutTransaction is not participating in a transaction, the changes made within withTransaction will happen within a new transaction and shouldn’t be … Read more

Use abstract super class as parameter for Spring data repository

If you aren’t using table inheritance on the database side (e.g. super class table with descriminator column), AFAIK, and based off reading the JPA tutorial, this can’t be done (i.e. simply using @MappedSuperclass annotation for your abstract class) Mapped superclasses cannot be queried and cannot be used in EntityManager or Query operations. You must use … Read more

@OneToMany mappedBy maps to _____

Yes wrapper for javax.mail.Header is needed, in general you cannot persist directly arbitrary classes, especially not the ones that are not Serializable. Also they cannot be elements of list that designs relationship between entities. Value of mappedBy is name of the field that is owning side of bidirectional relationship. For a sake of example, let’s … Read more

What is difference between @Resource UserTransaction and EntityManager.getTransaction()

EJB are transactional components. The transaction can be managed either by the applicaiton server itself (CMT – container-managed transaction), or manually by yourself within the EJB (BMT – bean-managed transaction). EJB supports distributed transaction through the JTA specification. The distributed transaction is controlled using UserTransaction, which has methods begin, commit, rollback. With CMT, the application … Read more

JPA: DELETE WHERE does not delete children and throws an exception

DELETE (and INSERT) do not cascade via relationships in JPQL query. This is clearly spelled in specification: A delete operation only applies to entities of the specified class and its subclasses. It does not cascade to related entities. Luckily persist and removal via entity manager do (when there is cascade attribute defined). What you can … Read more

JpaRepository caches newly created object. How to refresh it?

If you are using Hibernate, this is the expected result. When you call translationRepository.saveAndFlush(translation) and translationRepository.findOne(t.getId()) one after the other, they hit the same Hibernate session which maintains a cache of all objects that it has worked on. Therefore, the second call simply returns the object passed to the first. There is nothing in those … Read more

Total row count for pagination using JPA Criteria API

Thanks Vladimir! I took your idea and used separate count query to use my existing array of predicates in it. Final implementation looks like this: CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Brand> cQuery = builder.createQuery(Brand.class); Root<Brand> from = cQuery.from(Brand.class); CriteriaQuery<Brand> select = cQuery.select(from); . . //Created many predicates and added to **Predicate[] pArray** . . CriteriaQuery<Long> cq … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)