boing icon indicating copy to clipboard operation
boing copied to clipboard

Fix h2 migration issue

Open prabhavpandey19 opened this issue 4 months ago • 2 comments

  • Fixed h2 migration path for flyway migration file
  • Updated query from JPA to Native query. ( This needs to be figured out; JPA entity mapping in jruby )

Short answer: the HQL/JPA queries failed because Hibernate never registered your JRuby Employee class as a managed entity, so “Employee” is unknown in HQL. This happens due to how JRuby classes are reified and how Spring Boot scans for entities. Why this happens here Your entity is defined in Ruby (EmployeeApp::Employee) and annotated at runtime. Hibernate only “sees” entities that are on the application’s primary sources/scan path at the moment the EntityManagerFactory is bootstrapped. With JRuby, class reification timing and package scanning don’t align the same as plain Java. Even though you set @Entity(name="Employee"), Hibernate didn’t register it → UnknownEntityException. Switching to native SQL works because it doesn’t depend on Hibernate’s managed-entity metadata. Ways to make JPA work (choose one) Minimal change (stay stable): keep the current native SQL in EmployeesController. It’s simple and avoids entity registration pitfalls. Make JPA work reliably:

prabhavpandey19 avatar Oct 09 '25 07:10 prabhavpandey19

I believe we can set up our entities to register themselves, correct? I played with part of this but perhaps did not register it early enough.

headius avatar Oct 14 '25 16:10 headius

I understand what you are doing here but I want to figure out how to get the JPA subsystem to see our entity classes as defined.

Hibernate only “sees” entities that are on the application’s primary sources/scan path at the moment the EntityManagerFactory is bootstrapped.

Ok, how do we make that happen? I have a patch here that makes sure the entity gets reified and registered as a primary source, but it still doesn't want to find it when we run the query:

https://github.com/headius/boing/pull/2/commits/f7906f9f16213885113b2f4dc1b1399bd2b96c59

headius avatar Oct 14 '25 17:10 headius