grails-core icon indicating copy to clipboard operation
grails-core copied to clipboard

Support for JSON columns

Open c256985 opened this issue 8 years ago • 25 comments

Oracle, Postgres and MySQL all have support for storing JSON in columns, and querying/indexing json data stored in those columns. I was wondering how JSON columns are supported in GORM? How do we map a column appropriately to deal with JSON data?

c256985 avatar Dec 06 '17 21:12 c256985

For Postgresql you could use the grails posgresql extension plugin

https://github.com/kaleidos/grails-postgresql-extensions

sdelamo avatar Dec 07 '17 09:12 sdelamo

That looks interesting. I also noticed that Hibernate seems to have support for JSON and JSONB column types across Oracle, Postgres and MySQL. https://vladmihalcea.com/2016/06/20/how-to-map-json-objects-using-generic-hibernate-types/

Support at the GORM-level would also be useful if it doesn't already exist.

c256985 avatar Dec 07 '17 15:12 c256985

FYI... https://twitter.com/objectcomputing/status/856556974636453888

jeffscottbrown avatar Dec 08 '17 13:12 jeffscottbrown

@jeffbrown does that mean you're considering adding support for JSON columns, or that you've added it?

c256985 avatar Dec 08 '17 17:12 c256985

does that mean you're considering adding support for JSON columns, or that you've added it?

@c256985 The former.

jeffscottbrown avatar Dec 09 '17 16:12 jeffscottbrown

@jeffbrown Do you have a particular release in mind yet?

c256985 avatar Dec 09 '17 19:12 c256985

Do you have a particular release in mind yet?

No.

We are gauging interest to find out if there is enough demand to justify investing in building support.

jeffscottbrown avatar Dec 09 '17 20:12 jeffscottbrown

@jeffbrown From what little I've read, it looks like Hibernate already has support for it. (Not that that helps you decide whether or not you have the user-demand for it).

It would mean that the developer would have to bypass GORM and go directly with Hibernate.

The only alternative that I see is to have some combination of an RDB and Mongo where the JSON-like data is stored in Mongo. The developer would have to munge the data together at the Service-level. And figure out some criteria-based approach to querying.

Either way, it's messy for developers.

c256985 avatar Dec 09 '17 20:12 c256985

+1 for JSON column support in GORM & Grails. (Oracle DB here.)

jasenj1 avatar Feb 27 '18 16:02 jasenj1

@jasenj1 what kind of alternative approaches have you considered?

c256985 avatar Feb 27 '18 16:02 c256985

@c256985 Currently we are using a varchar/string column and doing JSON-type actions in a Service (some of this could be moved to the Domain object definition, but I prefer to keep the domain objects lean).

jasenj1 avatar Feb 27 '18 16:02 jasenj1

+1 for JSON column support in GORM & Grails.

rajat333malhotra avatar Feb 27 '18 23:02 rajat333malhotra

+1 for JSON column support in GORM & Grails.

oliver-was-here avatar May 04 '18 14:05 oliver-was-here

+1 for JSON column support in GORM & Grails.

dburyak avatar Aug 05 '18 23:08 dburyak

+1 for JSON column support in GORM & Grails.

curd0 avatar Aug 13 '18 20:08 curd0

+1 for JSON column support in GORM & Grails.

AleAnonMallo avatar Sep 05 '18 21:09 AleAnonMallo

+1, y'all.

dustindclark avatar Oct 24 '18 02:10 dustindclark

+1 for JSON column support in GORM & Grails.

rkimaoui avatar Oct 29 '18 23:10 rkimaoui

Scheduled for GORM 7.0.. thanks for the feedback

graemerocher avatar Oct 30 '18 12:10 graemerocher

Hi @graemerocher, as there is RC2 availabe and I cannot find any docs in https://gorm.grails.org/7.0.x/hibernate/manual/ - is it still planned for 7.0.0 ? thanks a lot!

Edit: received a response via twitter: https://twitter.com/jeffscottbrown/status/1113853667994734599 👍

madmas avatar Apr 04 '19 13:04 madmas

Hi all, I come to this requirement many times, mainly to avoid creating new tables when I have hasMany of simple types like String, Long, etc. specially when I know those Lists of simple values will be small, but GORM generates a new table, joins are needed, etc. It would be great to just have an array or map of JSON type that can be automatically serialized and parsed on insert/query.

ppazos avatar May 12 '23 02:05 ppazos

Hit this issue looking for a way to search a JSON column in a domain object. I was able to use HQL with JSON_EXTRACT to achieve this:

Domain.executeQuery("""
  select 
      d
  from 
      Domain d 
  where
      and FUNCTION('JSON_EXTRACT',d.jsonColumn,'\$.jsonField') = :val
""",[val:1])

danieljoeblack avatar Jun 26 '23 18:06 danieljoeblack

Hi @graemerocher, as there is RC2 availabe and I cannot find any docs in https://gorm.grails.org/7.0.x/hibernate/manual/ - is it still planned for 7.0.0 ? thanks a lot!

Edit: received a response via twitter: https://twitter.com/jeffscottbrown/status/1113853667994734599 👍

That twitter link doesn't seem to work anymore. May I know the gist of the response?

jaunt avatar Mar 14 '24 15:03 jaunt

I'm hoping to add support for this in an upcoming gorm version. Likely it will be the version where we switch to JPA / not the one released with Grails 7.

jdaugherty avatar Nov 10 '24 02:11 jdaugherty

I know this has been a desired feature for a long time, though today it might be a deal breaker not to have support to JSON columns, since it's a common practice for today's complex requirements to have some kind of denormalization and document orientation inside a relational DB.

Though I don't know what's the workload required for the GORM to have this on its DSL and of course in the query APIs (dynamic filters and criteria builders), and also on the constraints. We also need to consider today's core team is 100% community based and there are not many contributors.

I would like to know if this isn't planned yet so I can look for alternatives, like @danieljoeblack shared, there is a workaround at the HQL level, though JSON_EXTRACT seems to be a MySQL function and might not work on other databases.

The other option is to actually have two databases, one relational and one JSON (Couch, Mongo, etc), and it seems that Grails can connect to different data sources and tell domain classes to use one or the other (https://stackoverflow.com/a/14894944/1644320), so this affect domain model design, but it's doable.

I think the second option might be the more reliable way right now, though it adds a new architectural component that needs to be managed, has extra costs, etc. Not ideal, specially for SQL guys :)

ppazos avatar May 25 '25 15:05 ppazos