Grails where-query using joda-time

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Grails where-query using joda-time

SlechtValk
Hi All,

A couple of weeks ago I posted the following question on StackOverflow, but haven't gotten any useful replies.
Maybe you can help:
----

We are using Grails 2.3.11 with the joda-time plugin 1.4.

I was trying to use a where query like this:
Form.where { year(dateCreated) == currYear }.list()

In this currYear is an integer and dateCreated is of type org.joda.time.DateTime

The result is this Exception:

org.springframework.dao.InvalidDataAccessResourceUsageException: Unsupported function [year] defined in query for property [datum] with type [class org.joda.time.DateTime]
    at org.grails.datastore.gorm.finders.DynamicFinder.applyDetachedCriteria(DynamicFinder.java:440)
    at grails.gorm.DetachedCriteria.withPopulatedQuery_closure10(DetachedCriteria.groovy:1201)
    at org.grails.datastore.gorm.GormStaticApi.withDatastoreSession_closure23(GormStaticApi.groovy:699)
    at org.grails.datastore.mapping.core.DatastoreUtils.execute(DatastoreUtils.java:302)
    at org.grails.datastore.gorm.AbstractDatastoreApi.execute(AbstractDatastoreApi.groovy:37)
    at org.grails.datastore.gorm.GormStaticApi.withDatastoreSession(GormStaticApi.groovy:698)
    at grails.gorm.DetachedCriteria.withPopulatedQuery(DetachedCriteria.groovy:1185)
    at grails.gorm.DetachedCriteria.list(DetachedCriteria.groovy:845)
    at grails.gorm.DetachedCriteria.list(DetachedCriteria.groovy:844)

It seems that functions like year() are not supported when using joda-time. Is this correct? Or am I doing something wrong?

How hard would it be at add support for this in the joda-time plugin? Or somewhere else?

When I change the dateCreated to a java.util.Date it works correctly.

We have the mapping in our Config.groovy:

// Added by the Joda-Time plugin:
grails.gorm.default.mapping = { "user-type" type: org.jadira.usertype.dateandtime.joda.PersistentDateTime, class: org.joda.time.DateTime }

--
Hans

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CAAAqaVihN3uzHJc5cnnbCArTkqBD5ECLmkrTnuLYPYTpvs2T%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grails where-query using joda-time

Jeff Scott Brown-3


On August 1, 2014 at 4:09:27 AM, Hans Bogaards ([hidden email]) wrote:

Hi All,

A couple of weeks ago I posted the following question on StackOverflow, but haven't gotten any useful replies.
Maybe you can help:
----

We are using Grails 2.3.11 with the joda-time plugin 1.4.

I was trying to use a where query like this:
Form.where { year(dateCreated) == currYear }.list()

In this currYear is an integer and dateCreated is of type org.joda.time.DateTime

The result is this Exception:

org.springframework.dao.InvalidDataAccessResourceUsageException: Unsupported function [year] defined in query for property [datum] with type [class org.joda.time.DateTime]
    at org.grails.datastore.gorm.finders.DynamicFinder.applyDetachedCriteria(DynamicFinder.java:440)
    at grails.gorm.DetachedCriteria.withPopulatedQuery_closure10(DetachedCriteria.groovy:1201)
    at org.grails.datastore.gorm.GormStaticApi.withDatastoreSession_closure23(GormStaticApi.groovy:699)
    at org.grails.datastore.mapping.core.DatastoreUtils.execute(DatastoreUtils.java:302)
    at org.grails.datastore.gorm.AbstractDatastoreApi.execute(AbstractDatastoreApi.groovy:37)
    at org.grails.datastore.gorm.GormStaticApi.withDatastoreSession(GormStaticApi.groovy:698)
    at grails.gorm.DetachedCriteria.withPopulatedQuery(DetachedCriteria.groovy:1185)
    at grails.gorm.DetachedCriteria.list(DetachedCriteria.groovy:845)
    at grails.gorm.DetachedCriteria.list(DetachedCriteria.groovy:844)

It seems that functions like year() are not supported when using joda-time. Is this correct?


Yes, I believe so. 







JSB


-- 
Jeff Scott Brown 
[hidden email]pivotal.io

Find The Cause ~ Find The Cure 
http://www.autismspeaks.org/ 

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/etPan.53db8f82.3ebb814e.2770%40JSB-MBP-August-2012.local.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grails where-query using joda-time

SlechtValk
How hard would it be at add support for this in the joda-time plugin?
Or somewhere else?
--
Hans

On 1 August 2014 15:00:50 CEST, Jeff Scott Brown <[hidden email]> wrote:


On August 1, 2014 at 4:09:27 AM, Hans Bogaards ([hidden email]) wrote:

Hi All,

A couple of weeks ago I posted the following question on StackOverflow, but haven't gotten any useful replies.
Maybe you can help:
----

We are using Grails 2.3.11 with the joda-time plugin 1.4.

I was trying to use a where query like this:
Form.where { year(dateCreated) == currYear }.list()

In this currYear is an integer and dateCreated is of type org.joda.time.DateTime

The result is this Exception:

org.springframework.dao.InvalidDataAccessResourceUsageException: Unsupported function [year] defined in query for property [datum] with type [class org.joda.time.DateTime]
    at org.grails.datastore.gorm.finders.DynamicFinder.applyDetachedCriteria(DynamicFinder.java:440)
    at grails.gorm.DetachedCriteria.withPopulatedQuery_closure10(DetachedCriteria.groovy:1201)
    at org.grails.datastore.gorm.GormStaticApi.withDatastoreSession_closure23(GormStaticApi.groovy:699)
    at org.grails.datastore.mapping.core.DatastoreUtils.execute(DatastoreUtils.java:302)
    at org.grails.datastore.gorm.AbstractDatastoreApi.execute(AbstractDatastoreApi.groovy:37)
    at org.grails.datastore.gorm.GormStaticApi.withDatastoreSession(GormStaticApi.groovy:698)
    at grails.gorm.DetachedCriteria.withPopulatedQuery(DetachedCriteria.groovy:1185)
    at grails.gorm.DetachedCriteria.list(DetachedCriteria.groovy:845)
    at grails.gorm.DetachedCriteria.list(DetachedCriteria.groovy:844)

It seems that functions like year() are not supported when using joda-time. Is this correct?


Yes, I believe so. 







JSB


-- 
Jeff Scott Brown 
[hidden email]pivotal.io

Find The Cause ~ Find The Cure 
http://www.autismspeaks.org/ 


--
Sent from my Moto G with K-9 Mail. Please excuse my brevity.

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/a4762fa0-b7f7-4a82-8ab6-680e1aa1f9e6%40email.android.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grails where-query using joda-time

Jeff Scott Brown-3


On August 2, 2014 at 1:43:55 PM, Hans Bogaards ([hidden email]) wrote:

How hard would it be at add support for this in the joda-time plugin?
Or somewhere else?
--


I don’t think it would be very easy to do this in the plugin without making some changes to the code that currently compiles “where” queries.  However, I think making the changes there instead of in the plugin would likely be pretty straight forward.  If you like, file a feature request in the form of a JIRA and one of us will dig into it and possibly implement a solution. 



JSB
-- 
Jeff Scott Brown 
[hidden email]pivotal.io

Find The Cause ~ Find The Cure 
http://www.autismspeaks.org/ 

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/etPan.53ddb06c.6b8b4567.3a3f%40JSB-MBP-August-2012.local.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grails where-query using joda-time

fabio.oshiro

Try to put sql formula config inside domain mapping:

Integer year

static constraints = {
year nullable: true
}

static mapping = {
year formula: 'YEAR(SETTLEMENT_DATE)' // database specific?
}

full domain code: https://github.com/fabiooshiro/grails-reporting-js/blob/master/grails-app/domain/grails/reporting/js/Sale.groovy



On Sunday, August 3, 2014 12:45:51 AM UTC-3, jbrown wrote:


On August 2, 2014 at 1:43:55 PM, Hans Bogaards (<a href="javascript:" target="_blank" gdf-obfuscated-mailto="sDxx7p_vG2YJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">hbog...@...) wrote:

How hard would it be at add support for this in the joda-time plugin?
Or somewhere else?
--


I don’t think it would be very easy to do this in the plugin without making some changes to the code that currently compiles “where” queries.  However, I think making the changes there instead of in the plugin would likely be pretty straight forward.  If you like, file a feature request in the form of a JIRA and one of us will dig into it and possibly implement a solution. 



JSB
-- 
Jeff Scott Brown 
<a href="javascript:" style="font-family:helvetica;line-height:normal" target="_blank" gdf-obfuscated-mailto="sDxx7p_vG2YJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">jbr...@<a href="http://pivotal.io" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fpivotal.io\46sa\75D\46sntz\0751\46usg\75AFQjCNFaivYO9ybx-2kAd2JvXtp1y8vmLQ';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fpivotal.io\46sa\75D\46sntz\0751\46usg\75AFQjCNFaivYO9ybx-2kAd2JvXtp1y8vmLQ';return true;">pivotal.io

Find The Cause ~ Find The Cure 
<a href="http://www.autismspeaks.org/" style="font-family:helvetica;line-height:normal" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.autismspeaks.org%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHLOilSQBYB1lzLN6Ms6K6DtQY5DQ';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.autismspeaks.org%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHLOilSQBYB1lzLN6Ms6K6DtQY5DQ';return true;">http://www.autismspeaks.org/ 

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/1659d29c-c013-4c27-8f6e-a6db1ffba26b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grails where-query using joda-time

Jeff Scott Brown-3


On August 3, 2014 at 3:21:04 PM, Fabio Issamu Oshiro ([hidden email]) wrote:


Try to put sql formula config inside domain mapping:

Integer year

static constraints = {
year nullable: true
}

static mapping = {
year formula: 'YEAR(SETTLEMENT_DATE)' // database specific?
}



I don’t think that addresses the original question which is about using the year() method inside of a “where” query when the property is a joda date.



JSB
-- 
Jeff Scott Brown 
[hidden email]pivotal.io

Find The Cause ~ Find The Cure 
http://www.autismspeaks.org/ 

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/etPan.53de9d68.6b8b4567.4715%40JSB-MBP-August-2012.local.
For more options, visit https://groups.google.com/d/optout.