Skip to content
Advertisement

Tag: hibernate

Criteria Restriction by date field

I have 2 tables, Partner and Visit. A partner can have many visits, also various in same day. I need to create a Criteria restriction to know how many days the Partner has visits since a given date. So, 2 or more visits in same date must be only one. Can this be done only by Criteria and Restrictions?? I

java.lang.IllegalStateException: Multiple representations of the same entity with @ManyToMany 3 entities

I have 3 entities with ManyToMany relationships: Role Entity: Permission Entity: Functionality Entity: I did the following: I have created 3 functionalities: Then created 2 permissions: Then created a role: I am getting the following exception: java.lang.IllegalStateException: Multiple representations of the same entity [com.persistence.entity.admin.Functionality#1] are being merged. Detached: [com.persistence.entity.admin.Functionality@4729256a]; Detached: [com.persistence.entity.admin.Functionality@56ed25db] Answer Fixed it by removing CascadeType.MERGE on Permission entity

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’t instantiate class using Hibernate createQuery

I’m trying to use hibernate to create objects, which are not domain models, but I get a incomprehensible error message. My Java code: The class: Stacktrace: The schema for the table: Versions: Frankly, i’m clueless about why it cannot instantiate this class. Answer You get a NullPointerException in the constructor, so the time argument that your query retrieves from the

Spring Boot + JPA : Column name annotation ignored

I have a Spring Boot application with dependency spring-boot-starter-data-jpa. My entity class has a column annotation with a column name. For example: SQL generated by this created test_name as the columns name. After looking for a solution I have found that spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy solved the problem (column name is taken from column annotation). Still, my question is why without naming_strategy set

Advertisement