Hibernate table not mapped error in HQL query

The exception message says: Books is not mapped [SELECT COUNT(*) FROM Books]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: Books is not mapped [SELECT COUNT(*) FROM Books] Books is not mapped. That is, that there is no mapped type called Books. And indeed, there isn’t. Your mapped type is called Book. It’s mapped to a table called Books, … Read more

Postgresql UUID supported by Hibernate?

This can be solved by adding the following annotation to the UUID: import org.hibernate.annotations.Type; … @Type(type=”pg-uuid”) private java.util.UUID itemUuid; As to why Hibernate doesn’t just make this the default setting, I couldn’t tell you… UPDATE: There still seem to be issues using the createNativeQuery method to open objects that have UUID fields. Fortunately, the createQuery … Read more

Hibernate – A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance

Check all of the places where you are assigning something to sonEntities. The link you referenced distinctly points out creating a new HashSet but you can have this error anytime you reassign the set. For example: public void setChildren(Set<SonEntity> aSet) { this.sonEntities = aSet; //This will override the set that Hibernate is tracking. } Usually … Read more

In which case do you use the JPA @JoinTable annotation?

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: org.hibernate.AnnotationException: Associations marked as mappedBy must not define database mappings like @JoinTable or @JoinColumn Let’s pretend that you have an … Read more

How to map calculated properties with JPA and Hibernate

JPA doesn’t offer any support for derived property so you’ll have to use a provider specific extension. As you mentioned, @Formula is perfect for this when using Hibernate. You can use an SQL fragment: @Formula(“PRICE*1.155”) private float finalPrice; Or even complex queries on other tables: @Formula(“(select min(o.creation_date) from Orders o where o.customer_id = id)”) private … Read more