I am trying to delete a large number of rows from MOTHER thanks to a JPQL query. The Mother class is defined as follows: As you can see, the Mother class has “children” and when executing the following query: an exception is thrown: Of course, I could first select all the objects I want to delete and retrieve them into
Tag: hibernate
How can I cascade delete a collection which is part of a JPA entity?
In one of my jobs I have the following code: This always fails to delete the entity with the following error: The DELETE statement conflicted with the REFERENCE constraint “FK966F0D9A66DB1E54”. The conflict occurred in database “TFADB”, table “dbo.MonthlyReport_categories”, column ‘MonthlyReport_id’. How can I specify the mapping so the elements from the categories collection get deleted when the report is deleted?
When and how to use hibernate second level cache?
I have trouble understanding when hibernate hits the second level cache and when does it invalidate the cache. This is what I currently understand: Second level cache stores entities between …
Java / Hibernate – Write operations are not allowed in read-only mode
I’ve been having an annoying exception a lot lately, and after some research on Google and this forum I still haven’t found an answer that could solve my problem. Here’s the thing – sometimes, I get the following error when trying to update or create a new object with hibernate: What is really strange is that, sometimes when updating an
How to properly determine whether an “exists” JPA Criteria Query clause returned true or false?
I don’t know how to perform a JPA criteria query that returns with a boolean output. The goal is to have a criteria query that looks like this when rendered on Oracle: The where exists (…) part I performed with a subquery. I’m struggling with the external query. The practical use of this is to determine whether that subquery in
Why does hibernate/ehcache second level cache always miss within the same session?
I have a long-running EntityManager which I periodically clear(). I have a read-write cache configured on one of my entities. I have done some investigation and I can see that the entity is present in the cache. I can even see a cache hit from net.sf.ehcache.Cache.searchInStoreWithStats(). However, ehcache will not return the entity if its timestamp is later than the
hibernate or oracle support for timelines?
We have a requirement for persisting, using Hibernate, versioned Java objects into an Oracle database such that each version has a valid-from and valid-until timestamp. This is so we can query for objects as-at a specific time. Does Hibernate or Oracle 11g (or anything else) provide anything that would simplify this? Answer Have a look at Hibernate Envers The Envers
How to use object oriented programming with Hibernate?
While using ORM tools such as Hibernate, I’ve found it is advantageous to keep all business logic out of my business objects and instead keep it in a service layer. The service layer creates the business object POJOs, manipulates them, and uses DAOs to save them. But isn’t this in a way taking a step backwards from the object oriented
In which case do you use the JPA @JoinTable annotation?
In which case do you use the JPA @JoinTable annotation? Answer EDIT 2017-04-29: As pointed to by some of the commenters, the JoinTable example does not need the mappedBy annotation attribute. In fact, recent versions of Hibernate refuse to start up by printing the following error: Let’s pretend that you have an entity named Project and another entity named Task
What’s the advantage of load() vs get() in Hibernate?
Can anyone tell me what’s the advantage of load() vs get() in Hibernate? Answer Whats the advantage of load() vs get() in Hibernate? load() get() Only use load() method if you are sure that the object exists. If you are not sure that the object exist, then use one of get() methods. load() method will throw an exception if the