Someone asked me to answer the following StackOverflow question, and, because the question is very interesting from an SQL perspective, I decided to turn the answer it into a blog post.
In this article, we are going to see how to map a JPA
@ManyToOne association to the result of a SQL query using the Hibernate-specific
Continue reading “How to map a JPA @ManyToOne relationship to a SQL query using the Hibernate @JoinFormula annotation”
After I wrote the article about inheriting properties from a base class entity using
@MappedSuperclass, I got an avalanche of opinions, but this one from Lukas deserves a blog post:
@MappedSuperclass has its benefit, allowing you to reuse even the
@Id mapping, as well as being more lenient towards Hibernate-specific auto-generated properties like
@GeneratedValue, using Embeddable types is the other JPA alternative for reusing a bunch of properties among multiple entities.
In this article, we are going to see how we can reuse several audit-related properties using
@Embeddable and another awesome JPA feature,
Continue reading “How to audit entity modifications using the JPA @EntityListeners, @Embedded, and @Embeddable annotations”
Hibernate comes with many additions to the standard JPA specification. One such example is the
@GeneratorType annotation which allows you to customize the way a given entity property value is automatically generated.
If you’re using Spring Data, you can simply use the
@LastModifiedBy annotations and the annotated entity properties are going to be populated with the currently logged user.
If you’re not using Spring Data, then you can easily emulate the same behavior using the Hibernate-specific
@GeneratorType annotation and the
ValueGenerator callback mechanism.
Continue reading “How to emulate @CreatedBy and @LastModifiedBy from Spring Data using the @GeneratorType Hibernate annotation”
Last week, Burkhard Graves asked me to answer the following StackOverflow question:
And, since he wasn’t convinced about my answer:
I decided to turn it into a dedicated article and explain how UPSERT and MERGE work in the top 4 most common relational database systems: Oracle, SQL Server, PostgreSQL, and MySQL.
Continue reading “How do UPSERT and MERGE work in Oracle, SQL Server, PostgreSQL and MySQL”