Welcome to Mastertheboss, your go-to resource for enterprise Java development, middleware administration, and DevOps. Explore practical, step-by-step tutorials covering WildFly and JBoss EAP configuration, Keycloak identity management, Quarkus microservices, Jakarta EE, Docker, and OpenShift deployments. Whether you need help setting up SSL/TLS certificates, performance tuning, or integrating enterprise frameworks, find hands-on solutions for your architecture.
Using Inheritance with Hibernate JPA. Featured articles: Mapping Table per Concrete Class Using Table per subclass strategy Using table per class hierarchy Learn the key differences between Hibernate and...
One of the core addition of Java 8 is the Date Time API. As most of you probably know, Java has been missing a consistent approach for Date and Time. This approach solves some of the common issues issues...
This is a tutorial about creating a Java application using Hibernate ORM, Eclipse and MySQL Database. Hibernate is an object/relational mapping tool for Java environments. What does it mean the term object/relational...
@SoftDelete annotation, introduced in Hibernate version 6.4, provides first-class support for soft deletes, allowing to logically mark rows rows as deleted without actually removing them from the Database....
In this article we will learn how to implement a One to Many Entity Relation between two objects in an Hibernate/JPA application. In RDBMS terms, a one-to-many relationship exists when one record in table...
In Java Persistence API (JPA), the Many-to-Many relationship represents a common scenario where multiple instances of one entity are associated with multiple instances of another entity. This tutorial...
This tutorial shows how to create a JPA project using a Maven archetype and how to modify it in order to use Hibernate 4 JPA Provider and MySQL. By using the mvn archetype:generate command you are able...
When working with JPA (Java Persistence API) and defining entity classes, it’s crucial to avoid using reserved words as identifiers for attributes or table names. Failure to do so may lead to SQL syntax...
When using this strategy, the superclass has a table and each subclass has a table that contains only un-inherited properties: the subclass tables have a primary key that is a foreign key of the superclass....
JPA Entity Listeners are a powerful feature of the Java Persistence API (JPA) that allow developers to specify callback methods for certain events that occur in an entity’s lifecycle. These events include...
In object-oriented programming, inheritance allows you to create hierarchies of related classes. When mapping these class hierarchies to a relational database using the Java Persistence API (JPA), you...
In this tutorial, we will explore how to utilize JPA’s table per class hierarchy strategy to map a class hierarchy to a denormalized database table. The table per class hierarchy strategy allows multiple...
Hibernate Search is an extension of Hibernate, a popular Object-Relational Mapping (ORM) framework for Java applications. It provides full-text search capabilities by integrating with powerful search libraries...
Joining tables in SQL is the foundation of a relational database, as joins allow you to actually model relationships between tables. In plain JDBC, joins between tables are composed using native SQL statements....
In this updated article we will learn how to configure Hibernate Second Level Caches with Jakarta Persistence API to optimize database interactions. The primary objective is to minimize the frequency of...
The Java Persistence API allows you to define multiple persistence units, each of which can map to a separate database. In order to use multiple Database, simply define a persistent-unit for each one in...
By default the persistence unit are available in the java: Context. If you wish to make them available also in the global naming Context you have to add two properties to your persistence.xml configuration...
This is a handy cheatsheet for JPA developers with a collection of most common persistence.xml configurations. How to define JDBC Connection settings in persistence.xml How to declare external Entity classes...
In order to debug the Persistence Service in WildFly you can increase the org.jboss.as.jpa logging in order to gather the following information: Example: In order to enable TRACE, open the configuration...
In JPA (Java Persistence API) and Hibernate applications, queries can sometimes take a long time to execute, especially when working with large data sets. To avoid long-running queries, it’s important...
A fairly common question for developers approaching Object Relational Mapping (ORM) tools like Hibernate is what is the difference between Hibernate and JPA. In this article we are going to explain it...
In this short tutorial we will show how to use variables in your persistence.xml so that you can dynamically specify the data source which is used by our application. In WildFly the simplest and most elegant...
The JPA Criteria API is a powerful library, which is well adapted for implementing multi-criteria search functionalities where queries must be built on the fly. For example it can be used to return data...
This article is a walkthrough the Hibernate and JPA Named Query interface and how you can use it to externalize common Hibernate and JPA specification lets you externalize query strings to the mapping...
Native Queries are typically used to leverage some optimizations/features of your database which are not available through HQL/JPQL. Consider the following example: The above SQL statement leverages a...
Let’s learn how to invoke a Stored Procedure from Hibernate and JPA applications. Supposing you have the following Oracle Stored procedure: Invoking it from Hibernate requires mapping the Stored Procedure...
This article will teach you how to limit the number of records that your Hibernate/JPA Application returns from a Resultset of data. Fetching a large result set can be a challenge for your User Interface...
In order to show the SQL which Hibernate generates behind the hoods, you need to enable a property in your configuration file. If you are developing your applications with JPA, all you need to set the...
Returning large sets of data from your queries is an issue for many applications. It is virtually impossible to display a huge entire result in a single page so applications should be able to display a...
JPA native queries allow developers to use native SQL statements in their JPA application. You can use these queries to access specific features of a database or to optimize performance by using the database’s...
With Hibernate’s and JPA powerful query facilities, you can express almost everything you typically need to express in SQL, but in object-oriented terms—using classes and properties of classes. In this...
ScrollableResults requires the underlying Hibernate API for the scrolling but you can use all the features of JPA querying. There are different modes available in ScrollableResults: FORWARD_ONLY : It requests...
In this tutorial we will show how you can create an Hibernate 6 application using annotations. For this purpose we will use a basic Maven archetype and we will enhance so that it uses Hibernate dependencies...
In the former Hibernate tutorial we have shown how to create a simple standalone application XML configuration files to map Entities. In this short tutorial we will learn how to replace the Hibernate’s...
Jakarta Persistence API (JPA) is a Java specification for accessing, persisting, and managing data between Java objects/classes and a relational database. It is a part of the Jakarta EE platform, and it...
In this article, we will introduce Hibernate ORM, which is the de facto standard object-relational mapping framework for Java applications. At the end of it, you will learn how to develop Hibernate applications...
Welcome to our JPA hello world tutorial, where we’ll guide you through the basics of Java Persistence API (JPA). Follow along as we demonstrate step-by-step instructions, best practices, and practical...
Hibernate lets you override every single SQL statement generated with CRUD Operations. We have already covered native SQL query usage in this tutorial Using native Queries with Hibernate and JPA but you...
In this tutorial we will learn how to create new Type safe instances of an Objects simply using the EJB QL in your Query. By default, the select clause picks which objects and properties to return in the...
Here is a quick tip which shows how you can count your Database records using a NamedQuery in JPA. Here is the Named Query: Then, you can run the Named Query from any class which has access to the Entity...
@javax.persistence.Lob can be used to specify that the annotated field should be represented as BLOB (binary data) in the DataBase. A Lob may be either a binary or character type. Common use of @Lob is...
In this tutorial, we’ll explore the @org.hibernate.annotations.Entity annotation and specifically focus on its dynamicInsert and dynamicUpdate properties. These properties can be highly useful in optimizing...
This tutorial will teach you how to configure and optimize the fetch type strategy used in your Jakarta EE / Hibernate applications. In JPA terms, the FetchType strategy defines strategies for fetching...
One of the key features of relational database is referential integrity which is maintained by the system by taking certain actions when referential constraints are violated. So for example what happens...
If you need to select which columns need update when executing a CMP statement you can use the “updatable” attribute on the @Column annotation. Setting “updatable” = false will assume that the column is...
This short tutorial discusses how to map MySQL AutoIncrement Fields in Java using Jakarta Persistence API (JPA). In MySQL, the AUTO_INCREMENT field is a column attribute that allows the automatic generation...
An index is a data structure such as B-Tree that improves the speed of data retrieval on a table at the cost of additional writes and storage to maintain it. When using plain SQL, to add an index for a...
Filtering data is one of the most common Task of an application. This is usually achieved by adding WHERE clauses to your queries. In case the filters are defined dynamically by the user it becomes a more...
In this tutorial we will demonstrate how to set up Hibernate One-to-One Mapping between two Database tables. We will show how to create and deploy four applications using different approaches to set up...
This article discusses how to configure a JDBC Connection Pool in Hibernate applications covering both Hibernate managed applications and Hibernate Native applications. A JDBC connection pool is a set...
Composite keys are a group of columns in the database, whose values together make a unique value. When using Hibernate or JPA applications there are two main strategies to map a Composite Primary Key....
You can enable Hibernate statistics by setting the property hibernate.generate_statistics in the persistence.xml of your application: For Hibernate native application, you need to include the above property...
This is a short article to learn how to use Hibernate connection properties (username, JDBC URL etc.) in your persistence.xml to drive your connection to the Database As you know from the article Java...
In order to access Hibernate objects from a JPA application you can use the unwrap method available in the EntityManager and EntityManager Factory class: This method can be used to gain access of JPA-vendor-specific...