Master detail

45 views
Skip to first unread message

oceanfront

unread,
Jun 28, 2011, 10:41:47 AM6/28/11
to grails-jaxrs-discuss
I've been mucking about with grails-jaxrs for a few days now. Very
cool!

I managed to get createdDate and lastUpdated stuff working so that PUT
works.

I'm now exploring a project which has a master-detail (one to many)
relationship.
When I request the master record, I get the IDs of the child records.
(shallow copy).
Is there a simple way to get a deep copy, or would a custom provider
be needed?

Further to this, what is the recommended way to POST new master detail
records? Can this be done with a single POST (to make it
transactional) or should the master record get POSTed first, and then
the detail records?

If there is a way to make a single POST work, I'd be happy to
contribute the project as a sample.

Thanks!


Martin Krasser

unread,
Jun 28, 2011, 11:16:17 AM6/28/11
to grails-jax...@googlegroups.com
Hi,

Am 28.06.11 16:41, schrieb oceanfront:


> I've been mucking about with grails-jaxrs for a few days now. Very
> cool!

Great, thanks for trying it!

> I managed to get createdDate and lastUpdated stuff working so that PUT
> works.

Great! This is definitely something that is painfully missing in the
plugin. Would be great if you could share some code snippets or provide
a patch (clone -> change -> pull request).

I also thought about adding support for If-modified-since or
Last-modified headers but ... no time so far ...

> I'm now exploring a project which has a master-detail (one to many)
> relationship.
> When I request the master record, I get the IDs of the child records.
> (shallow copy).
> Is there a simple way to get a deep copy, or would a custom provider
> be needed?

You'll need a custom provider at the moment.

> Further to this, what is the recommended way to POST new master detail
> records? Can this be done with a single POST (to make it
> transactional) or should the master record get POSTed first, and then
> the detail records?

Currently yes. Otherwise you'll need a custom provider as well.

> If there is a way to make a single POST work, I'd be happy to
> contribute the project as a sample.

I'd love to see a contribution for that (also for deep copies when
GETting records). Let me know if you need further help.

Cheers,
Martin

> Thanks!
>
>

--
Martin Krasser

blog: http://krasserm.blogspot.com
code: http://github.com/krasserm
twitter: http://twitter.com/mrt1nz

Eric Sawler

unread,
Jun 28, 2011, 11:33:26 AM6/28/11
to grails-jax...@googlegroups.com
To get a deep clone on GET, simply add:
grails.converters.json.default.deep=true
grails.converters.xml.default.deep=true

to Config.groovy. This results in xml with a deep copy.

If I try to post the copy back (after removing ids) I get a 
"Provided id of the wrong type for class" exception for the detail class.

I suspect if I can figure out why this is happening, it (POST) may work as is. GORM is supposed to be able to figure out the back references from detail to master.

If you'd like, I can zip this up and send it. (stuck in the airport..)

Could this be related to string vs long 
in DomainObjectReaderSupport class?

PS As for the date stuff, it needs to be added at the project level. As soon as I'm back in the office I can document it for you. (it's in another project)


--
Eric Sawler
President

Novex Software Development Inc.
8743 Commercial St.
New Minas, NS
B4N 3C4

Ph: (888)-542-1813 x 1836
Fax: (902)-542-0848


Martin Krasser

unread,
Jun 28, 2011, 11:52:40 AM6/28/11
to grails-jax...@googlegroups.com


Am 28.06.11 17:33, schrieb Eric Sawler:
To get a deep clone on GET, simply add:
grails.converters.json.default.deep=true
grails.converters.xml.default.deep=true

to Config.groovy. This results in xml with a deep copy.

thanks for the hint, didn't know that.


If I try to post the copy back (after removing ids) I get a 
"Provided id of the wrong type for class" exception for the detail class.

I suspect if I can figure out why this is happening, it (POST) may work as is. GORM is supposed to be able to figure out the back references from detail to master.

If you'd like, I can zip this up and send it. (stuck in the airport..)

Could this be related to string vs long 
in DomainObjectReaderSupport class?
 
I'll take a closer look as soon as I can.



PS As for the date stuff, it needs to be added at the project level. As soon as I'm back in the office I can document it for you. (it's in another project)

Great, thanks

Martin Krasser

unread,
Jun 29, 2011, 1:15:37 AM6/29/11
to grails-jax...@googlegroups.com


Am 28.06.11 17:33, schrieb Eric Sawler:
To get a deep clone on GET, simply add:
grails.converters.json.default.deep=true
grails.converters.xml.default.deep=true

to Config.groovy. This results in xml with a deep copy.

If I try to post the copy back (after removing ids) I get a 
"Provided id of the wrong type for class" exception for the detail class.

I suspect if I can figure out why this is happening, it (POST) may work as is. GORM is supposed to be able to figure out the back references from detail to master.

If you'd like, I can zip this up and send it. (stuck in the airport..)

Could this be related to string vs long 
in DomainObjectReaderSupport class?

This can only be a problem if your domain classes use id types other than Long. Please send me a failing test (or a sample app) for reproducing the problem.

Martin Krasser

unread,
Aug 31, 2011, 2:46:49 AM8/31/11
to grails-jax...@googlegroups.com
A brief update on this. I'm currently working on getting deep XML and JSON conversions working properly in grails-jaxrs. For rendering XML and JSON responses, everything works fine using

grails.converters.json.default.deep=true
grails.converters.xml.default.deep=true

as Eric mentioned, but parsing (nested) XML requests fails. This is because of http://jira.grails.org/browse/GRAILS-6981 which is fixed with Grails 2.0.0.M1. With JSON, deep conversion of requests (i.e. parsing of nested entities) works fine.

I'm tracking deep domain object conversions in http://code.google.com/p/grails-jaxrs/issues/detail?id=49

Cheers,
Martin


Am 28.06.11 17:33, schrieb Eric Sawler:
To get a deep clone on GET, simply add:
Reply all
Reply to author
Forward
0 new messages