bug in DomainClassArtefactHandler#doIsDomainClassCheck ?

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

bug in DomainClassArtefactHandler#doIsDomainClassCheck ?

wgillett
I'm trying to use existing JPA-annotated Java domain classes in a Grails app, registering them via hibernate.cfg.xml. The app runs fine but unit testing doesn't work, mocking the Java classes results in "GrailsConfigurationException: Cannot add Domain class [class com.claritasgenomics.domain.Assay]. It is not a Domain!"

Stepping through the Grails 2.3.4 code, the method doIsDomainClassCheck ultimately decides that the Java class is not a domain class. It checks for an @Entity annotation, which the Java class has, but the Groovy code is looking for grails.persistence.Entity, not javax.persistence.Entity, so that check fails. But there's an alternative route to get a Java class to pass this test: declare id and version fields, which every proper domain object should have. Here's the relevant code:

testClass.getDeclaredField(GrailsDomainClassProperty.IDENTITY);
testClass.getDeclaredField(GrailsDomainClassProperty.VERSION);

Unfortunately, getDeclaredField only looks up fields declared in the class, not in the base class. Our code centralizes id and version fields in a common base class. Shouldn't the above code call getField rather than getDeclaredField, to allow these fields to appear in a base class, which is good DRY practice?
Reply | Threaded
Open this post in threaded view
|

Re: bug in DomainClassArtefactHandler#doIsDomainClassCheck ?

Graeme Rocher-2
Sounds like a bug, raise a JIRA. Pull requests welcome.

Cheers


On Fri, Dec 20, 2013 at 1:46 AM, wgillett <[hidden email]> wrote:
I'm trying to use existing JPA-annotated Java domain classes in a Grails app,
registering them via hibernate.cfg.xml. The app runs fine but unit testing
doesn't work, mocking the Java classes results in
"GrailsConfigurationException: Cannot add Domain class [class
com.claritasgenomics.domain.Assay]. It is not a Domain!"

Stepping through the Grails 2.3.4 code, the method doIsDomainClassCheck
ultimately decides that the Java class is not a domain class. It checks for
an @Entity annotation, which the Java class has, but the Groovy code is
looking for grails.persistence.Entity, not javax.persistence.Entity, so that
check fails. But there's an alternative route to get a Java class to pass
this test: declare id and version fields, which every proper domain object
should have. Here's the relevant code:

testClass.getDeclaredField(GrailsDomainClassProperty.IDENTITY);
testClass.getDeclaredField(GrailsDomainClassProperty.VERSION);

Unfortunately, getDeclaredField only looks up fields declared in the class,
not in the base class. Our code centralizes id and version fields in a
common base class. Shouldn't the above code call getField rather than
getDeclaredField, to allow these fields to appear in a base class, which is
good DRY practice?



--
View this message in context: http://grails.1312388.n4.nabble.com/bug-in-DomainClassArtefactHandler-doIsDomainClassCheck-tp4652699.html
Sent from the Grails - dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
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: bug in DomainClassArtefactHandler#doIsDomainClassCheck ?

wgillett
Never mind, on investigating further I realized that this method is in fact working perfectly. Sorry for the noise and I'll close the ticket.