Error in performing criteria with filter on object belonging to Composite ID

Asked

Viewed 32 times

1

An error occurs when I try to search the Car domain class by applying a filter on the Mark which is a FK and is part of the Composite ID.

class Carro implements Serializable {

    Marca marca
    LocalDate dataFabricacao

    static constraints = {
        marca nullable: false
        dataFabricacao nullable: false
    }

    static mapping = {
        table "carro"
        dynamicUpdate true

        id composite: ["marca", "dataFabricacao"], generator: "assigned"
        marca column: "cod_marca"

        version false
    }

}


class Marca {

    Long id
    
    static mapping = {
        table 'marca'
        dynamicUpdate true

        id column: "cod_marca", generator: "sequence", params: [sequence: 'seq_cod_marca']

        version false
    }

    static constraints = {
        id maxSize: 6
    }   
    
}


List<Carro> carroList = Carro.createCriteria().list {
    marca {
        idEq(18L)
    }

    fetchMode('marca', FetchMode.JOIN)
}

The following error occurs in the terminal: Error | 2021-01-29 10:46:27,763 [http-nio-8080-exec-9] ERROR util.Jdbcexceptionreporter - ORA-00904: "MARCA1_"." COD_MARCA": invalid identifier

The SQL that runs is this one:

select
    this_.cod_marca as cod1_22_0_,
    this_.data_fabricacao as data2_22_0_
from
    carros this_ 
where
     (
         marca1_.cod_marca=?
     )

I wonder if there is any way to apply this filter or if it is not possible with the tag object belonging to the Composite ID

Hibernate version: 3.6.10.19

Grails version: 2.5.6

Java version: 1.8.0_281

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.