For the life of me I cannot seem to get relationships to work on mapped tables with Grails. I have two domains I am trying to join, Resources and Cassettes. A Resource can have many Cassettes.
If i run the code below using scaffolding I get an error "Unknown column 'this_.cassette_id' in 'field list'". If i try to define the cassette_id in the mapping I get a fatal error upon compilation.
Can any wise Grails wizard set me on the correct path, I am new to this and have tried practically tried every method I can find to make this valid.
//resource definition
package edu.place.project
class Resource {
    String title
    String number
    String type
    Cassette cassette
    static hasMany  = [cassette : Cassette ]
    static mappedBy = [cassette : "hvt"]
    static mapping = {
            table "Resources"
    version false
            columns {
                    id column : "resourceI开发者_JAVA百科dentifier2"
                    title column: "title"
                    number column: "extentNumber"
                    type column: "extentType"
            }  
    }
    static constraints = {
    }
}
//Cassette definition
package edu.place.project
class Cassette {
    String id
    String type
    String numCode
    String hvt
    static belongsTo = Resource
    static mapping = {
            table "ArchDescriptionInstances"
            version false
            columns {
                    id column : "barcode", type : String
                    type column : "userDefinedString2"
                    numCode column : "container1AlphaNumIndicator"
                    hvt column : "userDefinedString1"
            }
    }
     static constraints = {
            barcode(unique : true)
     }
}
It's probably because you have:
class Resource {
    Cassette cassette
    static hasMany = [cassette: Cassette]
}
These two definitions conflict with each other. The hasMany implicitly tries to create a Set (collection) called cassette on your domain, but you've explicitly defined it as a Cassette.
Try removing the Cassette cassette and see what happens. I don't think you need it for the model you've described.
As an aside, you might also consider renaming the field to cassettes since it's a collection, rather than a singular object.
After these, your domains (the relationship parts, anyway) might look like this:
class Resource {
    static hasMany = [cassettes: Cassette]
}
class Cassette {
    Resource resource
    static belongsTo = Resource
}
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论