Answering questions on the Hibernate forum is a neverending source of inspiration. The following question is about joining unrelated entities using entity queries, and this post is going to explain how you can do it when using JPA and Hibernate.
Continue reading “How to JOIN unrelated entities with JPA and Hibernate”
Lukas Eder has posted a very interesting question on Stack Overflow, asking about a way of getting access to the binding metadata between entity mappings and database tables.
While I have previously answered a similar question using this article, I realized that case was much simpler since it only extracted the database metadata. In this article, you are going to see how easily you can get the bridge information between your JPA entities and the underlying database schema.
Continue reading “How to get the entity mapping to database table binding metadata from Hibernate”
As I explained in this StackOverflow question, mapping calculated properties is very easy with JPA and Hibernate.
In this post, I’m going to demonstrate how you can derive some entity property based on one or multiple persistent entity attributes.
Continue reading “How to map calculated properties with JPA and Hibernate @Formula annotation”
When fetching an entity, all attributes are going to be loaded as well. This is because every entity attribute is implicitly marked with the
@Basic annotation whose default fetch policy is
However, the attribute fetch strategy can be set to
FetchType.LAZY, in which case the entity attribute is loaded with a secondary select statement upon being accessed for the first time.
@Basic(fetch = FetchType.LAZY)
This configuration alone is not sufficient because Hibernate requires bytecode instrumentation to intercept the attribute access request and issue the secondary select statement on demand.
Continue reading “The best way to lazy load entity attributes using JPA and Hibernate”
The JHipster development team wants to expose Fluent Interface entity building methods for their JPA entities, so they asked me if this is going to work with JPA and Hibernate. While JPA is rather strict about entity getters and setter, Hibernate is more lenient in this regard.
Continue reading “Fluent API entity building with JPA and Hibernate”