Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Hibernate does not automatically control or replace Weld initialization in Java SE. Weld starts the CDI container; Hibernate separately starts persistence services such as an EntityManagerFactory or SessionFactory. They affect one another only when application code, a CDI extension, or an integration library explicitly connects their lifecycles.
That connection can still make Hibernate errors appear as Weld startup failures, increase total startup time, or prevent the CDI application from becoming ready. The decisive question is not whether Hibernate is on the classpath, but where and when the application creates the Hibernate factory.
The two startup lifecycles
| Component | Responsibility | Typical Java SE bootstrap |
|---|---|---|
| Weld | CDI bean discovery, injection, scopes, events, interceptors, decorators, and lifecycle callbacks | SeContainerInitializer or Weld’s Weld/WeldContainer API |
| Hibernate ORM | Entity metadata, SQL generation, persistence contexts, sessions, and persistence services | Persistence.createEntityManagerFactory(...) or native Hibernate APIs |
| JDBC driver | Database connectivity | Application classpath and Hibernate configuration |
| Transaction manager | Transaction coordination, particularly for JTA | Separate Java SE library or managed runtime |
CDI SE can be bootstrapped with SeContainerInitializer, while Weld also provides its own Java SE bootstrap APIs and launcher. Hibernate’s Jakarta Persistence bootstrap independently reads the persistence configuration and builds an EntityManagerFactory. Neither operation inherently invokes the other.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →See the Jakarta EE Tutorial’s CDI SE bootstrap documentation, the Weld Java SE reference, and Hibernate’s bootstrap documentation.
What a typical integrated startup looks like
main()
├─ initialize Weld
│ ├─ discover CDI bean archives
│ ├─ load CDI extensions
│ ├─ validate injection points
│ └─ complete CDI deployment
├─ obtain an application bean
├─ create EntityManagerFactory
│ ├─ locate META-INF/persistence.xml
│ ├─ process entity and mapping metadata
│ ├─ configure JDBC and dialect services
│ └─ build the Hibernate factory
└─ run the application
This is only one possible order. Hibernate may start before Weld, during CDI initialization, after the container has started, or on first use. The order is determined by application code and integration components, not by a universal Weld–Hibernate contract.
Does putting Hibernate on the classpath start it?
Usually, no. Hibernate dependencies make provider classes available to the classloader, but they do not by themselves create an EntityManagerFactory, open a persistence unit, or connect to a database.
Keep these events separate:
- Adding Hibernate and its dependencies to the classpath.
- Weld discovering CDI beans.
- Weld loading CDI extensions.
- Hibernate reading
META-INF/persistence.xml. - Creating an
EntityManagerFactoryorSessionFactory. - Opening database connections.
A dependency can contain CDI extensions, and those extensions can participate in container initialization. Weld documents portable extensions as components that observe container lifecycle events and add or modify beans. That is an integration effect, not proof that Hibernate ORM itself has replaced Weld’s bootstrap process. See the Weld portable extensions guide.
Where Hibernate and Weld actually intersect
A CDI lifecycle callback
If an application creates the factory in an application-scoped bean, Hibernate startup becomes part of CDI bean initialization:
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
@ApplicationScoped
public class PersistenceBootstrap {
private EntityManagerFactory emf;
@PostConstruct
void start() {
emf = Persistence.createEntityManagerFactory("app");
}
public EntityManagerFactory factory() {
return emf;
}
}
In this arrangement, a missing persistence unit, invalid mapping, unavailable database, bad dialect, or missing JDBC driver can abort bean initialization. The resulting top-level exception may mention Weld even though the deepest cause is Hibernate or JDBC. Startup also includes Hibernate’s metadata-processing time.
The important distinction is that @PostConstruct created the coupling. Hibernate is not intrinsically part of Weld; application code placed Hibernate bootstrap inside a CDI lifecycle callback.
A CDI producer
A producer centralizes factory creation and allows CDI services to inject the result:
Rank #2
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Disposes;
import jakarta.enterprise.inject.Produces;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
@ApplicationScoped
public class PersistenceProducer {
@Produces
@ApplicationScoped
EntityManagerFactory createFactory() {
return Persistence.createEntityManagerFactory("app");
}
void close(@Disposes EntityManagerFactory emf) {
emf.close();
}
}
The disposer gives CDI a defined place to close the factory. Do not assume that a producer always runs eagerly or always runs lazily: creation depends on its scope and when the produced bean is resolved. The producer makes the factory CDI-managed, but it does not automatically define transaction boundaries or create a safe, universal shared EntityManager.
A startup observer or CDI extension
An observer can deliberately start or verify persistence after a CDI startup event. A portable extension can participate even earlier in the CDI deployment lifecycle, register beans, or provide integration services. These approaches are useful for reusable infrastructure but make ordering and diagnostics more complex.
When an extension or observer creates Hibernate during container startup, database and mapping failures can prevent Weld from reaching a usable state. The application should document that behavior rather than treating it as an implicit platform feature.
Weld does not automatically provide container-managed JPA in Java SE
In a full Jakarta EE runtime, CDI and JPA are integrated by the surrounding container. That environment can provide facilities such as @PersistenceContext, @PersistenceUnit, transaction synchronization, and managed persistence contexts.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Plain Weld SE supplies CDI, not the complete Jakarta EE platform. Therefore, an injection point such as:
@Inject
EntityManager entityManager;
does not automatically become a working, transaction-aware persistence context merely because Weld and Hibernate are present.
In standalone Java SE, use an explicit producer, application-managed persistence, a supported CDI/JPA integration layer, or a runtime that deliberately supplies these services. Weld documents JpaInjectionServices as an SPI for environments that want to provide JPA injection support; it is not a guarantee that plain Weld SE supplies a provider, transaction manager, or persistence context. See the Weld Java EE integration guide and its integration SPI documentation.
Hibernate’s Java SE bootstrap
The standard Jakarta Persistence call is:
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("app");
Hibernate locates the named persistence unit in META-INF/persistence.xml on the runtime classpath, then processes entity mappings and persistence properties. A Java SE application must align its persistence API, provider, JDBC driver, Java version, and configuration.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
For example, a resource-local persistence unit may contain JDBC properties like these:
<persistence xmlns="https://jakarta.ee/xml/ns/persistence" version="3.2">
<persistence-unit name="app" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>example.Customer</class>
<properties>
<property name="jakarta.persistence.jdbc.url"
value="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"/>
<property name="jakarta.persistence.jdbc.driver"
value="org.h2.Driver"/>
<property name="jakarta.persistence.jdbc.user" value="sa"/>
<property name="jakarta.persistence.jdbc.password" value=""/>
</properties>
</persistence-unit>
</persistence>
The namespace and schema version must match the API generation used by the application. Do not silently combine older javax.persistence examples with modern jakarta.persistence dependencies.
Does Hibernate make Weld slower?
It can make overall application startup slower when Hibernate is initialized on that path. Hibernate must process persistence metadata, mappings, dialect and JDBC services, and sometimes database-related configuration. If this happens inside a CDI callback or producer resolution, the delay appears in a Weld-related startup trace.
That does not mean Hibernate’s entity scanning is Weld’s bean discovery. Weld discovers CDI beans according to CDI archive and discovery rules; Hibernate processes persistence-unit and entity metadata according to JPA and Hibernate rules. They may run close together, but they are different scanners and different lifecycles.
Whether beans.xml is present, its bean-discovery-mode, and any programmatic bean registration determine what Weld discovers. Adding beans.xml does not make a Hibernate persistence unit CDI-managed. See the CDI SE discovery documentation.
Choosing a standalone integration pattern
Explicit application service
This is often the clearest design for a command-line, desktop, or batch application:
Rank #4
public final class PersistenceService implements AutoCloseable {
private final EntityManagerFactory emf =
Persistence.createEntityManagerFactory("app");
public void save(Object entity) {
EntityManager em = emf.createEntityManager();
try {
em.getTransaction().begin();
em.persist(entity);
em.getTransaction().commit();
} catch (RuntimeException ex) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
throw ex;
} finally {
em.close();
}
}
@Override
public void close() {
emf.close();
}
}
The factory is long-lived; an EntityManager is created for a unit of work and closed afterward. This approach provides transparent ownership and simple resource-local transactions, at the cost of more manual wiring.
CDI-managed factory
Use a producer when application services already depend on CDI. Pair it with a disposer, define how entity managers are obtained, and make transaction boundaries explicit. Never treat one shared EntityManager as a universal application singleton or assume it is safe to use across threads.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsHibernate describes the EntityManager and Session as persistence-context APIs in which entities can be transient, managed, detached, or removed. Those states and unit-of-work boundaries should guide the scope of your persistence objects. See Hibernate’s persistence-context documentation.
Custom integration
A CDI extension or integration library can provide consistent injection semantics, but it must also handle lifecycle ordering, transactions, shutdown, classloaders, and error reporting. It may rely on Weld-specific SPIs rather than CDI alone.
Use a full runtime when the requirements demand it
If the application needs standard container-managed JPA, JTA, request-scoped persistence contexts, transaction synchronization, or security integration, a full Jakarta EE runtime or a framework that explicitly supplies those facilities may be more appropriate. Hibernate itself supports Java SE; the distinction is that a managed runtime supplies more integration services.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Eager, lazy, or separate initialization?
| Choice | Use it when | Main trade-off |
|---|---|---|
| Eager Hibernate startup | Bad mappings or an unavailable database should fail fast, or readiness requires a verified factory. | The entire application may fail before becoming usable. |
| Lazy startup | Some commands or modes do not use persistence, or database availability should not block CDI startup. | The first database operation is slower and needs robust error handling or retry logic. |
| Hibernate before Weld | Persistence should be validated independently and then passed into the application. | Manual wiring is required. |
| Hibernate from CDI | Persistence is deliberately application infrastructure managed by CDI. | Hibernate failures can be reported as CDI deployment or bean-creation failures. |
Choose one lifecycle owner. Avoid creating a factory in main() and again in a producer or startup observer. One long-lived EntityManagerFactory per intended application context is generally preferable to creating one for every operation.
Free tools Windows power users keep installed
One-click scans. No signup required.
Transactions in Java SE
Resource-local transactions are often the simplest standalone option:
Best Value
EntityTransaction tx = em.getTransaction();
tx.begin();
try {
// persistence work
tx.commit();
} catch (RuntimeException ex) {
if (tx.isActive()) {
tx.rollback();
}
throw ex;
}
JTA is appropriate when transactions must coordinate multiple resources, but it requires a JTA implementation and integration with the application. Adding Weld and Hibernate alone does not create a JTA transaction manager. Weld’s transaction services depend on the surrounding integration environment.
Diagnosing startup failures
| Symptom | Likely cause | What to check |
|---|---|---|
Unsatisfied EntityManager |
No CDI producer or JPA integration | Produce the required object, use application-managed JPA, or add a supported integration layer. |
No Persistence provider for EntityManager named ... |
Missing provider, wrong unit name, or namespace mismatch | Confirm META-INF/persistence.xml, the exact persistence-unit name, provider dependency, and API family. |
| Mapping exception during Weld startup | Hibernate was created in a CDI callback, observer, or producer | Inspect the deepest nested exception and validate entity mappings independently. |
| Startup is slow or hangs | Eager Hibernate bootstrap or database connection attempts | Check factory creation timing, JDBC configuration, connection pools, and whether lazy startup is preferable. |
| Hibernate starts twice | Multiple lifecycle owners or test/application contexts | Centralize factory creation and log each factory identity. |
NoClassDefFoundError, NoSuchMethodError, or linkage errors |
Incompatible Weld, CDI, persistence API, Hibernate, or Java versions | Inspect the resolved dependency tree and remove mixed version families. |
| Proxy or type errors involving persistence objects | Unsuitable CDI scope or a CDI client proxy passed to JPA | Avoid making entities normal CDI services and pass the underlying persistence object with an appropriate scope. |
When a Weld exception wraps a Hibernate exception, follow the cause chain to the lowest meaningful cause. The top-level message identifies where the application noticed the failure, not necessarily which subsystem caused it.
Version and namespace warning
Modern applications use jakarta.persistence.*; older Hibernate 5-era applications commonly use javax.persistence.*. These API families are not interchangeable. A project must align its CDI API, Weld version, persistence API, Hibernate provider, XML namespace, Java version, and JDBC driver.
Hibernate’s documentation page listed the 7.4 series as stable and 8.0 as development in the 2026 documentation snapshot. Release status can change, so identify the exact Hibernate version in build files and verify examples against that version’s documentation: Hibernate ORM documentation.
Shutdown is part of startup design
Use structured shutdown for the CDI container:
try (SeContainer container =
SeContainerInitializer.newInstance().initialize()) {
Application app = container.select(Application.class).get();
app.run();
}
Also close every factory your application owns:
emf.close();
If CDI owns the factory, use a disposer method. If a bootstrap class owns it, close it from that class. Failing to close the factory can leave connection pools, threads, or other resources alive after the application has finished.
The operational rule
In Java SE, Weld starts CDI and Hibernate starts persistence. Hibernate affects Weld’s apparent initialization only when the application initializes or exposes Hibernate during CDI deployment, bean creation, event processing, or extension execution. Decide explicitly whether Hibernate starts before, during, after, or independently of Weld; assign one lifecycle owner; define entity-manager and transaction boundaries; and close the factory at shutdown.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

