Upgrading from Hibernate 4 to Hibernate 5

32 views
Skip to first unread message

Jason Owen

unread,
May 17, 2017, 9:31:51 PM5/17/17
to psm-dev
The PSM was originally written against (and bundled) Hibernate 4. As part of PR#27, I upgraded from the vendored Hibernate 4 to the WildFly-provided Hibernate 5. This is causing some issues, since this is a major version change and has some incompatibilities.

The first major problem that I encountered relates to audit records. Activities such as creating new users are logged, but the way that IDs for the audit records and details were generated does not work under Hibernate 5, due to both deprecations and interface changes.

Yesterday, I was able to figure out some seed data so that I could log in, and today I was able to sort out the audit logging. This is very promising, because it suggests to me that many of the problems that I was encountering with the system can be addressed, and now I think I have a clear path forward. These exploratory changes are on a branch: wip-hibernate . Once I am more confident in these changes, I will recreate them in a less exploratory fashion and open a pull request. Hopefully this week!

Jason

Cecilia Donnelly

unread,
May 18, 2017, 11:34:53 AM5/18/17
to psm...@googlegroups.com
Thanks, Jason!


The PSM was originally written against (and bundled) Hibernate 4. As part of PR#27, I upgraded from the vendored Hibernate 4 to the WildFly-provided Hibernate 5. This is causing some issues, since this is a major version change and has some incompatibilities.

I wanted to highlight this because getting up to date with a modern version of Hibernate is part of our goal in this phase to update the PSM's dependencies.  We called out the Hibernate upgrade in particular in the approaches document from last phase.  So, making this change is a *huge* improvement.


Yesterday, I was able to figure out some seed data so that I could log in, and today I was able to sort out the audit logging. This is very promising, because it suggests to me that many of the problems that I was encountering with the system can be addressed, and now I think I have a clear path forward. These exploratory changes are on a branch: wip-hibernate .

Hurray!

More soon,
Cecilia

--
You received this message because you are subscribed to the Google Groups "psm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psm-dev+unsubscribe@googlegroups.com.
To post to this group, send email to psm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/psm-dev/102ea5aa-dcae-4159-8832-ba995c06c374%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Jason Owen

unread,
May 18, 2017, 9:10:49 PM5/18/17
to psm-dev
On Thursday, May 18, 2017 at 8:34:53 AM UTC-7, Cecilia Donnelly wrote:
Thanks, Jason!

The PSM was originally written against (and bundled) Hibernate 4. As part of PR#27, I upgraded from the vendored Hibernate 4 to the WildFly-provided Hibernate 5. This is causing some issues, since this is a major version change and has some incompatibilities.

I wanted to highlight this because getting up to date with a modern version of Hibernate is part of our goal in this phase to update the PSM's dependencies.  We called out the Hibernate upgrade in particular in the approaches document from last phase.  So, making this change is a *huge* improvement.

Thanks, that's a good reminder! I'm glad this is on-path, planned work.

Speaking of which, I was able to make some progress today. The wip-hibernate branch now supports creating more than one user, editing users, deleting users, and self-registration. Registration is one place where the mail session is used, so if you test this make sure that you're running Mailcatcher or similar.

As I was working on this, I found some more technical debt that we'll want to address: user IDs vs user names, partially-implemented account suspension, and not so great password handling. I'll keep adding issues as I learn more.

Thanks,
Jason

James Vasile

unread,
May 19, 2017, 6:39:26 AM5/19/17
to psm...@googlegroups.com
This is excellent progress, Jason. Thank you.
> --
> You received this message because you are subscribed to the Google Groups
> "psm-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to psm-dev+u...@googlegroups.com.
> To post to this group, send email to psm...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/psm-dev/55024a11-7f2c-45a8-ba96-4f781120312c%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
James Vasile
Open Tech Strategies
+1-212-444-2023

Jason Owen

unread,
May 19, 2017, 6:31:12 PM5/19/17
to psm-dev
Cecilia suggested that some background on Hibernate would be useful, which is a good call.

Previous versions of Hibernate relied on XML configuration to describe the relationship between Java objects and database tables. In our project, that's split into two pieces: the Hibernate-specific psm-app/cms-business-process/src/main/resources/META-INF/Medicaid.hbm.xml and the somewhat portable psm-app/cms-business-process/src/main/resources/META-INF/persistence.xml. The former includes a list of classes, their database tables, column names, column types, and relationships to other classes; the latter includes application server data source names, some Hibernate configuration options, and, notably, the embedded jBPM database tables.

jBPM is using the newer approach to configuration: annotations. Once annotations were introduced with Java 5, Hibernate and other ORMs started migrating to them, as they keep the already-tightly-coupled (in practice, if not necessarily in theory) configuration with the code. jBPM uses annotations, and by referring to the annotated classes in `persistence.xml`, Hibernate knows to examine the referenced classes' annotations.

In the wip-hibernate branch, I'm starting to port over classes from the hbm.xml file to annotations. I'm starting with the most broken first, but my goal is to get all of them, both for clarity and consistency's sake.
Message has been deleted

Jason Owen

unread,
May 26, 2017, 6:09:26 PM5/26/17
to psm-dev
This week I've continued converting classes/tables from XML to JPA annotations, and making sure they work with Hibernate 5 / PostgreSQL in the process. I've taken the approach of converting the most complicated cases first, on the theory that once those are prototyped, similar cases should be fairly mechanical. This results in less visible progress, but it should (I hope) also take less time overall, and allow for parallelization. Confounding that, however, is how closely everything is tied together, and the difficulty in testing one thing when it's linked to something else which is broken.

As I've been going through the things that are persisted to the database, I've been renaming tables and columns to follow the conventions I'm more familiar with and which I find more readable. I understand that's subjective, but at the moment I believe I'm the only one working on this with opinions on the subject, and will be working with it most closely in the near future. Some examples are: column `applicant_typ` -> `applicant_type`, column `id` -> `audit_record_id`, table `lu_provider_type` -> `provider_types`, and so on. Basically: try to have ID columns that include the table name, use whole, correctly spelled words, avoid Hungarian notation, use snake_case, and use plural table names. If you have opinions on any of this, I would love to hear them!

There are a few bits of complexity I haven't worked through yet: polymorphism, bags, and outer joins.

The former is implemented as a pair of columns to be an application-side foreign key to several different tables; ie, ('AgreementDocument', '02') -> agreement_documents(agreement_document_id=2). Aside from giving up database integrity by using real foreign keys on a link table, this is also breaking because PostgreSQL is reasonably saying "you can't compare a string to a number, stop it". I need to study the two instances of polymorphic tables to better understand what they're doing, but broadly speaking, my plan is to try to better represent these relationships in the database.

The latter two are less complicated, and so far have not caused any errors; I think I just need to study and understand what it's doing now and figure out how to do the same thing with annotations.

Overall, I think I'm getting close; barring any surprises, I hope to finish the hibernate migration next week!

Thanks,
Jason

Dan Schultz

unread,
May 29, 2017, 10:49:06 PM5/29/17
to psm...@googlegroups.com
Jason, just wanted to chime in and say that I'm not sure I fully understand the polymorphism challenge you're facing, but would love to help think through it if you have a moment tomorrow morning.

Best,
 - Dan

--
You received this message because you are subscribed to the Google Groups "psm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psm-dev+u...@googlegroups.com.
To post to this group, send email to psm...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Reply all
Reply to author
Forward
0 new messages