# An entityManagerFactory for multiple JVMs

**URL:** <https://discourse.hibernate.org/t/an-entitymanagerfactory-for-multiple-jvms/7621>\
**Category:** Hibernate ORM\
**Created:** [May 10, 2023, 9:49am UTC](https://discourse.hibernate.org/t/an-entitymanagerfactory-for-multiple-jvms/7621 "2023-05-10T09:49:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![boutss](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/boutss/32/1543_2.png) [@boutss](https://discourse.hibernate.org/u/boutss)\
**Post date:** [May 10, 2023, 9:49am UTC](https://discourse.hibernate.org/t/an-entitymanagerfactory-for-multiple-jvms/7621/1 "2023-05-10T09:49:45Z")

</div>

Hi,

I would like to save time on the construction of the entityManagerFactory for at least two reasons:

1. We have 300 overnight batches, and we don’t have the option to add 10 seconds x 300 batches = 50 minutes (we would need to reduce the number of batches, I admit ^^).
2. We also run a significant number of integration tests, which are increasingly time-consuming.

The idea is therefore to save time on the construction of the entityManagerFactory by serializing it, as shown here:

[Serializing the hibernate sessionfactory & deserialize it to improve startup time - Hibernate ORM - Hibernate](https://discourse.hibernate.org/t/serializing-the-hibernate-sessionfactory-deserialize-it-to-improve-startup-time/4086/1)

But from what I understood, the serialization of the entityManagerFactory is customized to be added to the EntityManagerFactoryRegistry for use via JNDI. So, it compromises my plan a bit.

Is it possible to build an entityManagerFactory in one JVM and utilize it in other JVMs?

Should a distributed cache be used to accomplish this?

Thank you !

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [May 10, 2023, 1:22pm UTC](https://discourse.hibernate.org/t/an-entitymanagerfactory-for-multiple-jvms/7621/2 "2023-05-10T13:22:21Z")

</div>

Use Quarkus for this purpose. It pre-builds parts of the `SessionFactory` during application build time and has hence a faster startup.

---

<div class="post-metadata">

**Author:** ![boutss](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/boutss/32/1543_2.png) [@boutss](https://discourse.hibernate.org/u/boutss)\
**Post date:** [May 10, 2023, 1:34pm UTC](https://discourse.hibernate.org/t/an-entitymanagerfactory-for-multiple-jvms/7621/3 "2023-05-10T13:34:47Z")

</div>

But can we use Quarkus, or a part of Quarkus, without questioning the entire integration of Hibernate?

Or do I have to migrate everything to Quarkus (with Quarkus dependencies instead of Hibernate) for that?

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [May 10, 2023, 3:46pm UTC](https://discourse.hibernate.org/t/an-entitymanagerfactory-for-multiple-jvms/7621/4 "2023-05-10T15:46:52Z")

</div>

No idea what kind of integration you are talking about, but there certainly are some limitations with respect to integrators in Quarkus, though it should all work fine in JVM mode.

---

<div class="post-metadata">

**Author:** ![boutss](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/boutss/32/1543_2.png) [@boutss](https://discourse.hibernate.org/u/boutss)\
**Post date:** [May 11, 2023, 9:45am UTC](https://discourse.hibernate.org/t/an-entitymanagerfactory-for-multiple-jvms/7621/5 "2023-05-11T09:45:35Z")

</div>

Regarding serialization, it is not possible due to the transient attributes… I just realized that!

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/hibernate/original/2X/1/15a44b83acd2d1e704b8622865bede18f8ad6f26.png)
