1
votes

Given:

  • User, File are domain classes
  • src/groovy/Container.groovy:

    class Container {
      User user
      File file
      Date dateCreated
    }
    
  • grails-app/domain/WithContainer.groovy:

    class WithContainer {
      Container c
      String text
    
      static embedded = ['c']
    }
    

I was aiming at mapping WithContainer to a table with the columns:

user_id | file_id | date_created | text

Is that achievable with GORM?

This setup yields:

org.hibernate.MappingException: Could not determine type for: User, at table: with_container, for columns: [org.hibernate.mapping.Column(c_user)]

Thanks

1
any reason to have Container not among domain classes? - injecteer
I just ran into the same issue with a scenario which I believe is more common - i.e. I have an Address class under src/groovy, which consists of 5 common address fields (street1, street2, city, zip, state) and is used as an embedded object in several domain objects (or even twice as billing/shipping address of one object). All address fields were strings, but I'd like to refactor it to actually be an instance of the "State" domain object rather than a "String". I think this is a valid use case and I'm wondering if it's possible or if I need to refactor the objects? - Rado

1 Answers

0
votes

Container is not a domain class because it isn't defined under grails-app/domain/.

It may be that you are confused about the embedded attribute. Properties in the embedded list are persistent properties for which you want all of their attributes stored in the same table as the owning class (WithContainer in your case), as opposed to being stored in their own table and referenced with foreign keys. The property still needs be an instance of a domain class though.