MCPcopy Index your code
hub / github.com/Blazebit/blaze-persistence

github.com/Blazebit/blaze-persistence @1.6.18

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.6.18 ↗ · + Follow
39,686 symbols 192,018 edges 5,144 files 7,799 documented · 20%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Build Status

Maven Central Zulip Chat

Javadoc - Core Javadoc - Entity-View Javadoc - JPA-Criteria

Blaze-Persistence

Blaze-Persistence is a rich Criteria API for JPA providers.

What is it?

Blaze-Persistence is a rich Criteria API for JPA providers that aims to be better than all the other Criteria APIs available. It provides a fluent API for building queries and removes common restrictions encountered when working with JPA directly. It offers rich pagination support and also supports keyset pagination.

The Entity-View module can be used to create views for JPA entites. You can roughly imagine an entity view is to an entity, what a RDBMS view is to a table.

The JPA-Criteria module implements the Criteria API of JPA but is backed by the Blaze-Persistence Core API so you can get a query builder out of your CriteriaQuery objects.

With Spring Data or DeltaSpike Data integrations you can make use of Blaze-Persistence easily in your existing repositories.

Features

Blaze-Persistence is not only a Criteria API that allows to build queries easier, but it also comes with a lot of features that are normally not supported by JPA providers.

Here is a rough overview of new features that are introduced by Blaze-Persistence on top of the JPA model

  • Use CTEs and recursive CTEs
  • Use modification CTEs aka DML in CTEs
  • Make use of the RETURNING clause from DML statements
  • Use the VALUES clause for reporting queries and soon make use of table generating functions
  • Create queries that use SET operations like UNION, EXCEPT and INTERSECT
  • Manage entity collections via DML statements to avoid reading them in memory
  • Define functions similar to Hibernates SQLFunction in a JPA provider agnostic way
  • Use many built-in functions like GROUP_CONCAT, date extraction, date arithmetic and many more
  • Easy pagination and simple API to make use of keyset pagination

In addition to that, Blaze-Persistence also works around some JPA provider issues in a transparent way.

How to use it?

Blaze-Persistence is split up into different modules. We recommend that you define a version property in your parent pom that you can use for all artifacts. Modules are all released in one batch so you can safely increment just that property.

<properties>
    <blaze-persistence.version>1.6.17</blaze-persistence.version>
</properties>

Alternatively you can also use our BOM in the dependencyManagement section.

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.blazebit</groupId>
            <artifactId>blaze-persistence-bom</artifactId>
            <version>${blaze-persistence.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>    
    </dependencies>
</dependencyManagement>

Quickstart

If you want a sample application with everything setup where you can poke around and try out things, just go with our archetypes!

Core-only archetype:

mvn archetype:generate "-DarchetypeGroupId=com.blazebit" "-DarchetypeArtifactId=blaze-persistence-archetype-core-sample" "-DarchetypeVersion=1.6.17"

Entity view archetype:

mvn archetype:generate "-DarchetypeGroupId=com.blazebit" "-DarchetypeArtifactId=blaze-persistence-archetype-entity-view-sample" "-DarchetypeVersion=1.6.17"

Spring-Data archetype:

mvn archetype:generate "-DarchetypeGroupId=com.blazebit" "-DarchetypeArtifactId=blaze-persistence-archetype-spring-data-sample" "-DarchetypeVersion=1.6.17"

Spring-Boot archetype:

mvn archetype:generate "-DarchetypeGroupId=com.blazebit" "-DarchetypeArtifactId=blaze-persistence-archetype-spring-boot-sample" "-DarchetypeVersion=1.6.17"

DeltaSpike Data archetype:

mvn archetype:generate "-DarchetypeGroupId=com.blazebit" "-DarchetypeArtifactId=blaze-persistence-archetype-deltaspike-data-sample" "-DarchetypeVersion=1.6.17"

Java EE archetype:

mvn archetype:generate "-DarchetypeGroupId=com.blazebit" "-DarchetypeArtifactId=blaze-persistence-archetype-java-ee-sample" "-DarchetypeVersion=1.6.17"

Core-only Jakarta archetype:

mvn archetype:generate "-DarchetypeGroupId=com.blazebit" "-DarchetypeArtifactId=blaze-persistence-archetype-core-sample-jakarta" "-DarchetypeVersion=1.6.17"

Entity view Jakarta archetype:

mvn archetype:generate "-DarchetypeGroupId=com.blazebit" "-DarchetypeArtifactId=blaze-persistence-archetype-entity-view-sample-jakarta" "-DarchetypeVersion=1.6.17"

Supported Java runtimes

All projects are built for Java 7 except for the ones where dependencies already use Java 8 like e.g. Hibernate 5.2, Spring Data 2.0 etc. So you are going to need a JDK 8 for building the project. The latest Java version we test and support is Java 21.

We also support building the project with JDK 9 and try to keep up with newer versions. If you want to run your application on a Java 9 JVM you need to handle the fact that JDK 9+ doesn't export the JAXB and JTA APIs anymore. In fact, JDK 11 removed the modules, so the command line flags to add modules to the classpath won't work.

Since libraries like Hibernate and others require these APIs you need to make them available. The easiest way to get these APIs back on the classpath is to package them along with your application. This will also work when running on Java 8. We suggest you add the following dependencies.

<dependency>
    <groupId>jakarta.xml.bind</groupId>
    <artifactId>jakarta.xml.bind-api</artifactId>

    <version>2.3.3</version>

    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>

    <version>2.3.3</version>

    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>jakarta.transaction</groupId>
    <artifactId>jakarta.transaction-api</artifactId>

    <version>1.3.3</version>

    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>jakarta.activation</groupId>
    <artifactId>jakarta.activation-api</artifactId>

    <version>1.2.2</version>

    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>jakarta.annotation</groupId>
    <artifactId>jakarta.annotation-api</artifactId>

    <version>1.3.5</version>

    <scope>provided</scope>
</dependency>

The jakarta.transaction and jakarta.activation dependencies are especially relevant for the JPA metamodel generation.

Supported environments/libraries

The bare minimum is JPA 2.0. If you want to use the JPA Criteria API module, you will also have to add the JPA 2 compatibility module. Generally, we support the usage in Java EE 6+ or Spring 4+ applications.

See the following table for an overview of supported versions.

Module Minimum version Supported versions
Hibernate integration Hibernate 4.2 4.2, 4.3, 5.0+, 6.2+, 7.1 (not all features are available in older versions)
EclipseLink integration EclipseLink 2.6 2.6 (Probably 2.4 and 2.5 work as well, but only tested against 2.6)
DataNucleus integration DataNucleus 4.1 4.1, 5.0
OpenJPA integration N/A (Currently not usable. OpenJPA doesn't seem to be actively developed anymore and no users asked for support yet)
Entity View CDI integration CDI 1.0 1.0, 1.1, 1.2, 2.0, 3.0
Entity View Spring integration Spring 4.3 4.3, 5.0, 5.1, 5.2, 5.3, 6.0
DeltaSpike Data integration DeltaSpike 1.7 1.7, 1.8, 1.9
Spring Data integration Spring Data 1.11 1.11 - 2.7, 3.1 - 3.5
Spring Data WebMvc integration Spring Data 1.11, Spring WebMvc 4.3 Spring Data 1.11 - 3.5, Spring WebMvc 4.3 - 6.2
Spring Data WebFlux integration Spring Data 2.0, Spring WebFlux 5.0 Spring Data 2.0 - 3.5, Spring WebFlux 5.0 - 6.2
Spring HATEOAS WebMvc integration Spring Data 2.2, Spring WebMvc 5.2 Spring Data 2.3+, Spring WebMvc 5.2+, Spring HATEOAS 1.0+
Jackson integration 2.8.11 2.8.11+
GraphQL integration 17.3 17.3+
JAX-RS integration Any JAX-RS version Any JAX-RS version
Quarkus integration 1.4.2 1.4+, 2.0+, 3.1+

Manual setup

For compiling you will only need API artifacts and for the runtime you need impl and integration artifacts.

See the core documentation for the necessary dependencies needed to setup Blaze-Persistence. If you want to use entity views, the entity view documentation contains a similar setup section describing the necessary dependencies.

Documentation

The current documentation is a reference manual and is split into a reference for the core module and for the entity-view module. At some point we might introduce topical documentation, but for now you can find articles on the Blazebit Blog

Core quick-start

First you need to create a CriteriaBuilderFactory which is the entry point to the core api.

CriteriaBuilderConfiguration config = Criteria.getDefault();
// optionally, perform dynamic configuration
CriteriaBuilderFactory cbf = config.createCriteriaBuilderFactory(entityManagerFactory);

NOTE: The CriteriaBuilderFactory should have the same scope as your EntityManagerFactory as it is bound to it.

For demonstration purposes, we will use the following simple entity model.

@Entity
public class Cat {
    @Id
    private Integer id;
    private String name;
    @ManyToOne(fetch = FetchType.LAZY)
    private Cat father;
    @ManyToOne(fetch = FetchType.LAZY)
    private Cat mother;
    @OneToMany
    private Set<Cat> kittens;
    // Getter and setters omitted for brevity
}

If you want to select all cats and fetch their kittens as well as their father you do the following.

cbf.create(em, Cat.class).fetch("kittens.father").getResultList();

This will create quite a query behind the scenes:

SELECT cat FROM Cat cat LEFT JOIN FETCH cat.kittens kittens_1 LEFT JOIN FETCH kittens_1.father father_1

An additional bonus is that the paths and generally every expression you write will get checked against the metamodel so you can spot typos very early.

JPA Criteria API quick-start

Blaze-Persistence provides an implementation of the JPA Criteria API what allows you to mostly code against the standard JPA Criteria API, but still be able to use the advanced features Blaze-Persistence provides.

All you need is a CriteriaBuilderFactory and when constructing the actual query, an EntityManager.

```java // This is a subclass of the JPA CriteriaBuilder interface BlazeCriteriaBuilder cb = BlazeCriteria.get(criteriaBuilderFactory); // A subclass of the JPA CriteriaQuery interface BlazeCriteriaQuery query = cb.createQuery(Cat.class);

// Do your JPA Criteria query logic with cb and query Root root = query.from(Cat.class); query.where(cb.equal(root.get(Cat_.name), "Felix"));

// Finally, transform the BlazeCriteriaQuery to the Blaze-Persistence Core CriteriaBuilder CriteriaBuilder builder = query.createCriteriaBuilder(entityManager); // From here on, you can use all the power of the Blaze-Persistence Core API

// And finally fetch the result List resultList = b

Extension points exported contracts — how you extend this code

Database (Interface)
@author Christian Beikov @since 1.6.7 [7 implementers]
integration/hibernate6-base/src/main/java/com/blazebit/persistence/integration/hibernate/base/Database.java
WithBuilder (Interface)
WithBuilder is a builder for common table expressions. Analog to com.querydsl.sql.WithBuilder. @param < [14 implementers]
integration/querydsl/expressions/src/main/java/com/blazebit/persistence/querydsl/WithBuilder.java
EntityViewQueryRunner (Interface)
Implementation is similar to org.apache.deltaspike.data.impl.handler.QueryRunner but was modified to work with e [16 implementers]
integration/deltaspike-data/impl-1.8/src/main/java/com/blazebit/persistence/deltaspike/data/impl/handler/EntityViewQueryRunner.java
EntityViewAwareRepositoryMetadata (Interface)
@author Christian Beikov @author Eugen Mayer @since 1.6.9 [26 implementers]
integration/spring-data/base-3.3/src/main/java/com/blazebit/persistence/spring/data/base/query/EntityViewAwareRepositoryMetadata.java
DeskView (Interface)
@author Moritz Becker @since 1.6.0 [151 implementers]
integration/quarkus/deployment/src/test/java/com/blazebit/persistence/integration/quarkus/deployment/multipleinstances/view/annotation/desk/DeskView.java
TestView1 (Interface)
@author Moritz Becker @since 1.2.0 [205 implementers]
integration/entity-view-spring/src/test/java/com/blazebit/persistence/integration/view/spring/views/sub1/TestView1.java
TestView (Interface)
@author Christian Beikov @since 1.0.0 [205 implementers]
integration/entity-view-cdi/src/test/java/com/blazebit/persistence/integration/view/cdi/TestView.java
EntityViewIdValueAccessor (Interface)
This interface is used to supply an entity view id from platform specific sources to the deserializer. The deserializer [67 …
integration/jackson/src/main/java/com/blazebit/persistence/integration/jackson/EntityViewIdValueAccessor.java

Core symbols most depended-on inside this repo

append
called by 8728
entity-view/processor/src/main/java/com/blazebit/persistence/view/processor/JavaType.java
add
called by 2417
entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/objectbuilder/ContainerAccumulator.java
select
called by 2368
core/api/src/main/java/com/blazebit/persistence/SelectBuilder.java
get
called by 2186
core/api/src/main/java/com/blazebit/persistence/spi/AttributeAccessor.java
get
called by 2157
entity-view/api/src/main/java/com/blazebit/persistence/view/metamodel/AttributePath.java
size
called by 1945
core/impl/src/main/java/com/blazebit/persistence/impl/util/SetView.java
from
called by 1450
core/api/src/main/java/com/blazebit/persistence/FromBuilder.java
where
called by 1287
core/api/src/main/java/com/blazebit/persistence/WhereBuilder.java

Shape

Method 33,600
Class 4,220
Interface 1,597
Function 157
Enum 112

Languages

Java100%
TypeScript1%
Kotlin1%

Modules by API surface

core/impl/src/main/java/com/blazebit/persistence/impl/AbstractCommonQueryBuilder.java210 symbols
integration/hibernate-5.6/src/main/java/com/blazebit/persistence/integration/hibernate/Hibernate56DelegatingDialect.java168 symbols
integration/hibernate-5.3/src/main/java/com/blazebit/persistence/integration/hibernate/Hibernate53DelegatingDialect.java162 symbols
integration/hibernate-5/src/main/java/com/blazebit/persistence/integration/hibernate/Hibernate5DelegatingDialect.java151 symbols
integration/hibernate-5.2/src/main/java/com/blazebit/persistence/integration/hibernate/Hibernate52DelegatingDialect.java150 symbols
core/parser/src/test/java/com/blazebit/persistence/parser/GeneralParserTest.java144 symbols
integration/hibernate-4.3/src/main/java/com/blazebit/persistence/integration/hibernate/Hibernate43DelegatingDialect.java141 symbols
jpa-criteria/impl/src/main/java/com/blazebit/persistence/criteria/impl/BlazeCriteriaBuilderImpl.java135 symbols
integration/hibernate-4.2/src/main/java/com/blazebit/persistence/integration/hibernate/Hibernate4DelegatingDialect.java133 symbols
entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/proxy/ProxyFactory.java119 symbols
core/impl/src/main/java/com/blazebit/persistence/impl/JoinManager.java112 symbols
entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/ManagedViewTypeImpl.java109 symbols

Datastores touched

(mysql)Database · 1 repos
information_schemaDatabase · 1 repos

For agents

$ claude mcp add blaze-persistence \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact