|
In Robert Fischer's book Grails Persistence with GORM and GSQL, he provides an example of embedding a class in a domain. In the example, he embeds class Name in class Foo. That example is fine as far as it goes, but because Name was defined in ./src/groovy, it is not a domain, thus constraints could not be defined within the class. Now, it may be possible to define constraints on the properties of the embedded from the parent (I have not tried, nor googled to find out), that is less than ideal if Name is likely to be embedded in several classes and the constraints should hold for all classes. If it is possible to define constraints for the class even though it is outside of the domain tree, please enlighten me.
Searching for solutions, it seems that you can define the class to be embedded in ./grails-app/domain, giving you the ability to define constraints. The problem with this solution, as I understand it, is that if the embedded class is only and always used as an embedded class, a table will be created but no data ever written to it. This could be confusing for those that are unfamiliar with the idiosyncracies of Grails, especially those that hit the tables directly via sql or from some other non-Grails application. If my understanding is correct, then why would one ever embed? I cannot believe the peformance hit for joining two tables is that great in one-to-one relationships. Am I wrong about this? Thanks! |
|
Embedding should not be your default solution: in general, one-to-one is the way to go.
Embedding is used for when there are conventions used over and over again in the database. I've seen dates stored as numbers "FOO_YR", "FOO_MON", "FOO_DAY", and currencies stored as "CENTS" and "CURCODE" (value in minimum denominational unit and the currency code). While you theoretically could manage that kind of structure through one-to-one mappings, you end up losing context and meaning for those fields: the resulting table doesn't mean much, and the domain object *really* doesn't mean anything. An alternative solution to the embedding problem space is Hibernate User Types, but those are more of a hassle than they're often worth. ~~ Robert. bill.turner wrote: > In Robert Fischer's book Grails Persistence with GORM and GSQL, he provides > an example of embedding a class in a domain. In the example, he embeds class > Name in class Foo. That example is fine as far as it goes, but because Name > was defined in ./src/groovy, it is not a domain, thus constraints could not > be defined within the class. Now, it may be possible to define constraints > on the properties of the embedded from the parent (I have not tried, nor > googled to find out), that is less than ideal if Name is likely to be > embedded in several classes and the constraints should hold for all classes. > If it is possible to define constraints for the class even though it is > outside of the domain tree, please enlighten me. > > Searching for solutions, it seems that you can define the class to be > embedded in ./grails-app/domain, giving you the ability to define > constraints. The problem with this solution, as I understand it, is that if > the embedded class is only and always used as an embedded class, a table > will be created but no data ever written to it. This could be confusing for > those that are unfamiliar with the idiosyncracies of Grails, especially > those that hit the tables directly via sql or from some other non-Grails > application. > > If my understanding is correct, then why would one ever embed? I cannot > believe the peformance hit for joining two tables is that great in > one-to-one relationships. Am I wrong about this? > > Thanks! > > ----- > Bill Turner > http://www.changent.com Groovy/Grails Talk -- ~~ Robert Fischer, Smokejumper IT Consulting. Enfranchised Mind Blog http://EnfranchisedMind.com/blog Check out my book, "Grails Persistence with GORM and GSQL"! http://www.smokejumperit.com/redirect.html --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Powered by Nabble | Edit this page |
