Restricted names for GORM object properties??

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Restricted names for GORM object properties??

alxndrsn
Is there a list of names that are restricted for GORM properties?

I am getting problems when setting constraints for a property called
`read` - when running a unit test I get the following exception:

|  groovy.lang.MissingMethodException: No signature of method:
badpropname.Ting.read() is applicable for argument types: () values:
[]
Possible solutions: read(java.io.Serializable),
load(java.io.Serializable), isRead(), create(), getId(), find()
    at badpropname.Ting$__clinit__closure1.doCall(Ting.groovy:8)
    at org.grails.datastore.mapping.config.groovy.MappingConfigurationBuilder.evaluate(MappingConfigurationBuilder.groovy:80)
    at org.grails.datastore.mapping.config.AbstractGormMappingFactory.createMappedForm(AbstractGormMappingFactory.java:63)
    at org.grails.datastore.mapping.keyvalue.mapping.config.GormKeyValueMappingFactory.createMappedForm(GormKeyValueMappingFactory.java:38)
    at org.grails.datastore.mapping.keyvalue.mapping.config.GormKeyValueMappingFactory.createMappedForm(GormKeyValueMappingFactory.java:27)
    at org.grails.datastore.mapping.keyvalue.mapping.config.KeyValuePersistentEntity.<init>(KeyValuePersistentEntity.java:35)
    at org.grails.datastore.mapping.keyvalue.mapping.config.KeyValueMappingContext.createPersistentEntity(KeyValueMappingContext.java:95)
    at org.grails.datastore.mapping.model.AbstractMappingContext.addPersistentEntityInternal(AbstractMappingContext.java:214)
    at org.grails.datastore.mapping.model.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:207)
    at grails.test.mixin.domain.DomainClassUnitTestMixin.mockDomain(DomainClassUnitTestMixin.groovy:147)
    at grails.test.mixin.domain.DomainClassUnitTestMixin.mockDomain(DomainClassUnitTestMixin.groovy:145)


This bug is recreatable with different properties (e.g. `get`,
`list`), and I can supply an example project.

This occurs for me on both Grails 2.0.3 and Grails 2.2.3.  Is this a
known problem?  Are there a list of properties which should not be
used?

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Restricted names for GORM object properties??

sergiomichels
If you look at the docs http://grails.org/doc/2.3.x/, in the right sidebar, all this names mentioned by you are methods of the domain class.

--
Sérgio Michels


On Mon, Oct 7, 2013 at 5:38 AM, Alex Anderson <[hidden email]> wrote:
Is there a list of names that are restricted for GORM properties?

I am getting problems when setting constraints for a property called
`read` - when running a unit test I get the following exception:

|  groovy.lang.MissingMethodException: No signature of method:
badpropname.Ting.read() is applicable for argument types: () values:
[]
Possible solutions: read(java.io.Serializable),
load(java.io.Serializable), isRead(), create(), getId(), find()
    at badpropname.Ting$__clinit__closure1.doCall(Ting.groovy:8)
    at org.grails.datastore.mapping.config.groovy.MappingConfigurationBuilder.evaluate(MappingConfigurationBuilder.groovy:80)
    at org.grails.datastore.mapping.config.AbstractGormMappingFactory.createMappedForm(AbstractGormMappingFactory.java:63)
    at org.grails.datastore.mapping.keyvalue.mapping.config.GormKeyValueMappingFactory.createMappedForm(GormKeyValueMappingFactory.java:38)
    at org.grails.datastore.mapping.keyvalue.mapping.config.GormKeyValueMappingFactory.createMappedForm(GormKeyValueMappingFactory.java:27)
    at org.grails.datastore.mapping.keyvalue.mapping.config.KeyValuePersistentEntity.<init>(KeyValuePersistentEntity.java:35)
    at org.grails.datastore.mapping.keyvalue.mapping.config.KeyValueMappingContext.createPersistentEntity(KeyValueMappingContext.java:95)
    at org.grails.datastore.mapping.model.AbstractMappingContext.addPersistentEntityInternal(AbstractMappingContext.java:214)
    at org.grails.datastore.mapping.model.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:207)
    at grails.test.mixin.domain.DomainClassUnitTestMixin.mockDomain(DomainClassUnitTestMixin.groovy:147)
    at grails.test.mixin.domain.DomainClassUnitTestMixin.mockDomain(DomainClassUnitTestMixin.groovy:145)


This bug is recreatable with different properties (e.g. `get`,
`list`), and I can supply an example project.

This occurs for me on both Grails 2.0.3 and Grails 2.2.3.  Is this a
known problem?  Are there a list of properties which should not be
used?

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Restricted names for GORM object properties??

alxndrsn
On 7 October 2013 17:04, Sergio Michels <[hidden email]> wrote:
> If you look at the docs http://grails.org/doc/2.3.x/, in the right sidebar,
> all this names mentioned by you are methods of the domain class.

I've noticed this, but it doesn't say that you can't have properties
and methods with the same name, does it?  Certainly that's not a
problem I've experienced in either Groovy or Java...

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Restricted names for GORM object properties??

sergiomichels
 Certainly that's not a problem I've experienced in either Groovy or Java

Correct. This happens because the constraints block is interpreted, and each line is considered a method call.

--
Sérgio Michels


On Mon, Oct 7, 2013 at 11:13 AM, Alex Anderson <[hidden email]> wrote:
On 7 October 2013 17:04, Sergio Michels <[hidden email]> wrote:
> If you look at the docs http://grails.org/doc/2.3.x/, in the right sidebar,
> all this names mentioned by you are methods of the domain class.

I've noticed this, but it doesn't say that you can't have properties
and methods with the same name, does it?  Certainly that's not a
problem I've experienced in either Groovy or Java...

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Restricted names for GORM object properties??

alxndrsn
On 7 October 2013 17:35, Sergio Michels <[hidden email]> wrote:
>>  Certainly that's not a problem I've experienced in either Groovy or Java
>
>
> Correct. This happens because the constraints block is interpreted, and each
> line is considered a method call.

But the problem *only* occurs in unit tests, so could it be a bug?

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Restricted names for GORM object properties??

sergiomichels
Can you share your unit test?

--
Sérgio Michels


On Tue, Oct 8, 2013 at 1:39 AM, Alex Anderson <[hidden email]> wrote:
On 7 October 2013 17:35, Sergio Michels <[hidden email]> wrote:
>>  Certainly that's not a problem I've experienced in either Groovy or Java
>
>
> Correct. This happens because the constraints block is interpreted, and each
> line is considered a method call.

But the problem *only* occurs in unit tests, so could it be a bug?

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Restricted names for GORM object properties??

alxndrsn
On 8 October 2013 15:34, Sergio Michels <[hidden email]> wrote:
> Can you share your unit test?

Project at: https://github.com/alxndrsn/grails-property-name-restriction

e.g. https://github.com/alxndrsn/grails-property-name-restriction/blob/master/test/unit/badpropname/TangTests.groovy
for https://github.com/alxndrsn/grails-property-name-restriction/blob/master/grails-app/domain/badpropname/Tang.groovy

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Restricted names for GORM object properties??

Jeff Scott Brown
In reply to this post by alxndrsn


On October 7, 2013 at 3:38:41 AM, Alex Anderson ([hidden email]) wrote:

Is there a list of names that are restricted for GORM properties?

No.  I think the list would be different for different persistence engines.



JSB

--
Jeff Scott Brown
[hidden email]

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|

Re: Restricted names for GORM object properties??

alxndrsn
On 8 October 2013 18:35, Jeff Scott Brown <[hidden email]> wrote:
> No.  I think the list would be different for different persistence engines.

I appreciate that some columns may need to be remapped for different
database engines (e.g. `read` is ok with H2, but not allowed with
MySQL).  The issue is that some names are not compatible *with grails
unit tests*, and this doesn't seem to be documented anywhere.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Restricted names for GORM object properties??

Graeme Rocher-2
Please raise a JIRA issue for this

Thx


On Wed, Oct 9, 2013 at 9:21 AM, Alex Anderson <[hidden email]> wrote:
On 8 October 2013 18:35, Jeff Scott Brown <[hidden email]> wrote:
> No.  I think the list would be different for different persistence engines.

I appreciate that some columns may need to be remapped for different
database engines (e.g. `read` is ok with H2, but not allowed with
MySQL).  The issue is that some names are not compatible *with grails
unit tests*, and this doesn't seem to be documented anywhere.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email





--
Graeme Rocher
Grails Project Lead
SpringSource
Reply | Threaded
Open this post in threaded view
|

Re: Restricted names for GORM object properties??

alxndrsn
Thanks Graeme - http://jira.grails.org/browse/GRAILS-10603

On 9 October 2013 11:52, Graeme Rocher <[hidden email]> wrote:

> Please raise a JIRA issue for this
>
> Thx
>
>
> On Wed, Oct 9, 2013 at 9:21 AM, Alex Anderson
> <[hidden email]> wrote:
>>
>> On 8 October 2013 18:35, Jeff Scott Brown <[hidden email]> wrote:
>> > No.  I think the list would be different for different persistence
>> > engines.
>>
>> I appreciate that some columns may need to be remapped for different
>> database engines (e.g. `read` is ok with H2, but not allowed with
>> MySQL).  The issue is that some names are not compatible *with grails
>> unit tests*, and this doesn't seem to be documented anywhere.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>
>
>
>
> --
> Graeme Rocher
> Grails Project Lead
> SpringSource

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Restricted names for GORM object properties??

SAgrawal31
In reply to this post by alxndrsn
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Restricted names for GORM object properties??

SAgrawal31
In reply to this post by alxndrsn
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Restricted names for GORM object properties??

Ian Roberts
On 15/11/2013 04:59, SAgrawal31 wrote:
> Yeah, I too have this kind of problem. I'm writing test case for a
> controller using domain class that have two property *first* and *last*

Exactly this problem came up on Stack Overflow yesterday, my solution
was to disambiguate the method calls in the constraints block using
"delegate", i.e.

static constraints = {
  delegate.first(nullable:true)
  delegate.last(nullable:true)
}

http://stackoverflow.com/a/19962381/592139

Question to the developers, is this an argument for making the
constraints closure DELEGATE_FIRST or would that cause more problems
that it would solve?

Ian

--
Ian Roberts               | Department of Computer Science
[hidden email]  | University of Sheffield, UK

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email