gotch4
gotch4

Reputation: 13259

How to query map properties in Hibernate?

I'm learning HQL and I've an object with a Map property like this:

    @ElementCollection
    @JoinTable(name = "InfoLicenzaOrdine", joinColumns = @JoinColumn(name = "infolicenza"))
    @Column(length = 64000)
    public Map<String, String> getInformazioniDiLicenza() {
        return informazioniDiLicenza;
    }

    public void setInformazioniDiLicenza(
            Map<String, String> informazioniDiLicenza) {
        this.informazioniDiLicenza = informazioniDiLicenza;
    }

Now an HQL query like:

 select ordine from Ordine ordine where ordine.informazioniDiLicenza['codiceAccisa1'] = 'IT00NOV00029W'

will return all the objects with that value for that particular key of the map. What if I just want all the objects with that value regardless of the key?

Upvotes: 1

Views: 4078

Answers (2)

semen
semen

Reputation: 161

In case when 'IT00NOV00029W' is stored by any key Ordine will be selected. Be carefull

Upvotes: 2

axtavt
axtavt

Reputation: 242686

select ordine from Ordine ordine 
    where 'IT00NOV00029W' in elements(ordine.informazioniDiLicenza) 

See also:

Upvotes: 1

Related Questions