These are chat archives for hibernate/hibernate-orm

30th
Oct 2017
Drew Spencer
@slugmandrew
Oct 30 2017 11:32
Hey everyone! I'm new here, and relatively unexperienced with hibernate. Have just started the process of migrating my domain model from google datastore to hibernate+postgres and hoping this is a friendly place to get advice when needed :)
ryan2049
@ryan2049
Oct 30 2017 11:46
Yes
Drew Spencer
@slugmandrew
Oct 30 2017 11:52
Cool, if anyone else has had the experience of migrating from a schemaless datastore to postgres I'd appreciate any pointers. Currently have set up my entities with basic annotations and generated the schema, working on how to use JSONB types for polymorphic subtypes. Ugh
Josiah Haswell
@josiahhaswell
Oct 30 2017 18:20
@slugmandrew Consider inheritance for polymorphic subtypes
Drew Spencer
@slugmandrew
Oct 30 2017 18:22
@josiahhaswell I've just managed to create my first UserType and register it so I can store basic json type
next step is jsonb type for polymporphic ones, right@
Josiah Haswell
@josiahhaswell
Oct 30 2017 18:25
@slugmandrew What exactly do you need to do? JSON is convenient for some things in Postgres, but if you're migrating to a RDBMS like Postgres, inheritance is more idomatic and portable for polymorphism
Well, and while Postgres implements inheritance natively, Hibernate implements it in a database-independent fashion via a few different techniques
Drew Spencer
@slugmandrew
Oct 30 2017 18:31
@josiahhaswell I think I need single-table inheritance with polymorphic subtypes (using jackson's subtype annotations)
Josiah Haswell
@josiahhaswell
Oct 30 2017 18:48
@slugmandrew ehhhh. Separate out your DB schema from your JSON schema.
Drew Spencer
@slugmandrew
Oct 30 2017 19:06
not sure what you mean
Josiah Haswell
@josiahhaswell
Oct 30 2017 19:09
@slugmandrew Create your DB schema first, then map them to JSON or whatever, because otherwise it's ambiguous as to whether you're having a Hibernate problem or a Jackson problem
Drew Spencer
@slugmandrew
Oct 30 2017 19:16
@josiahhaswell Issue is I have a rather complex domain model designed for a schemaless system and I'm trying to map it with JPA/Hibernate now as close as possible
I realise there are some things that won't fit perfectly but as I understand it JSONB types can be used to allow fully polymorphic classes as entity fields
It's real hard trying to think of the schema first when you've been thinking domain model first for so long :/
Josiah Haswell
@josiahhaswell
Oct 30 2017 19:59
@slugmandrew It's still going to be schemaless in Postgres if you're just using JSONB. Hibernate isn't the best tool for schemaless work
Drew Spencer
@slugmandrew
Oct 30 2017 20:29
@josiahhaswell wanna help me out with a suggestion?
btw most of the data is highly relational, just some properties are polymorphic
Josiah Haswell
@josiahhaswell
Oct 30 2017 20:47
@slugmandrew Sure--provide me the polymorphic entities and I'll suggest a schema
Steve Ebersole
@sebersole
Oct 30 2017 22:30
@MohsenEmami depending on the version you could remap Type.BIGINT SqlTypeDescriptor or provide a custom Dialect. a custom UserType "works" but would not affect every case
that SqlTypeDescriptor approach btw is much better in the 6.0 codebase
@josiahhaswell is storing UUID in pgsql really more efficient than storing as a number? its probably more efficient than a String/CHAR
I mean storing the UUID using its specific data type
Steve Ebersole
@sebersole
Oct 30 2017 22:40
@josiahhaswell btw, what I mentioned regarding SqlTypeDescriptor and 6.0 goes for your question as well. In fact that situation would already be handled by Hibernate automatically. The pgsql Dialect would register the pgsql-uuid SqlTypeDescriptor and that would be used