I have encountered many posts on the Internet about this specific error, and in all of them the programmer is using the wrong case on the attribute, but I don't think that's the case in my situation (or it is, and I simply don't know what to use, in which case your reply is appreciated). I have the following domain classes:
The 'WallpaperTag' class (containing the link between the 'Wallpaper' and 'Tagname' class, so multiple tags can be applied to a single wallpaper and vice versa):
class WallpaperTag implements Serializable {
Wallpaper wallpaper
Tagname tagname
static mapping = {
if (Environment.current != Environment.TEST) {
table name: 'JWS_JWS_WALLPAPERS_TAGS', schema: 'jws'
id composite: ['wallpaper', 'tagname']
columns {
wallpaper column: 'JWS_JWS_WAL_KEY', sqlType: 'INTEGER', length: 11, lazy: false
tagname column: 'JWS_JWS_TGN_KEY', sqlType: 'INTEGER', length: 11, lazy: false
}
}
version(false)
}
static constraints = {
wallpaper nullable: false, blank: false, maxSize: 11
tagname nullable: false, blank: false, maxSize: 11
}
WallpaperTag(Wallpaper wallpaper, Tagname tagname) {
this.wallpaper = wallpaper
this.tagname = tagname
}
}
The 'Tagname' class (containing the actual tag names that can be applied to a Wallpaper)
class Tagname {
String name
Purity purity
static mapping = {
if (Environment.current != Environment.TEST) {
table name: 'JWS_JWS_TAGNAMES', schema: 'jws'
id column: 'key', sqlType: 'INTEGER', generator: 'identity'
}
name column: 'NAME', sqlType: 'VARCHAR', length: 255
purity column: 'JWS_JWS_PUR_KEY', sqlType: 'INTEGER'
version(false)
}
static constraints = {
name nullable: false, blank: false
purity nullable: false, blank: false
}
Tagname(String name, Purity purity) {
this.name = name
this.purity = purity
}
}
Whenever I try to execute the following Hibernate query, the error occurs (error triggers on the "'tagname' {" line):
List<WallpaperTag> wallpaper_tags = (List<WallpaperTag>) WallpaperTag.createCriteria().list {
'tagname' {
inList('name', tags)
}
}
The error message itself:
Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [tagname] on this ManagedType [org.grails.guides.WallpaperTag]
Things I have tried to fix this issue:
- Refactored the 'Tagname' class to 'TagName' (capital N, to make it camelcase)
- Refactored the 'tagname' attribute to 'tagName' (capital N, to make it camelcase).
- Renamed the mapped column name from 'JWS_JWS_TGN_KEY' to 'JWSJWSTGNKEY' (I know this probably wasn't the issue, but still worth trying).
If anyone knows what the issue might be, your knowledge would be appreciated!