@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

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

Tool to Execute JPQL Queries?

Until Eclipse Dali gets a generic JPQL editor you can use Hibernate Tools. Hibernate Tools works with Dali and provides a HQL/JPQL query editor which uses Hibernate to execute the queries. An alternative would be to use the JPA Query Tool [JQT], an Interactive JPA query editor and runner. It might be closer to what … Read more

How do I do a JPQL SubQuery?

You need to test it with IN and subquery since both do work in JPQL (according to syntax reference they do work together). You may also look at MEMBER OF expressions. But there is a better approach in my opinion. Such queries are called correlated sub-queries and one can always re-write them using EXISTS: SELECT … Read more

Using the JPA Criteria API, can you do a fetch join that results in only one join?

Instead of root.join(…) you can use root.fetch(…) which returns Fetch<> object. Fetch<> is descendant of Join<> but it can be used in similar manner. You just need to cast Fetch<> to Join<> it should work for EclipseLink and Hibernate … Join<MyEntity, RelatedEntity> join = (Join<MyEntity, RelatedEntity>)root.fetch(“relatedEntity”); …

tech