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
Tag: hibernate
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 …
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 …
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 me…
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 ma…
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 an…
How to map Hibernate entity fields using camelCase to snake_case (underscore) database identifiers
I have database fields in underscore. I have entity fields in camelcase. I can’t change either of those. Is there something, maybe a class level annotation I can use to default entity column name annotations to the camelcase equivalent? for example, I have an entity like this: I dream of this: Answer Yo…
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 i…
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…
Hibernate – automatically delete children when updating parent
I have two tables. Site have a lot of Sectors. When I try to edit the list of sectors of a site, for example I have 3 sectors initially, so I delete one sector and I update the site. in the database are three sectors of the Site. Is it possible that the sectors are automatically deleted when I update