-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: HQL throws QueryException: could not resolve property
PostPosted: Thu Nov 16, 2017 7:25 pm 
Newbie

Joined: Thu Nov 16, 2017 7:16 pm
Posts: 3
Hi

I'm having a problem converting an sql query to HQL

This is mysql query

Code:
SELECT t.atos_idAtos, t1.dataAto, CONCAT_WS(' ', c.Nome, c.Apelido) AS clienteA, CONCAT_WS(' ', c1.Nome, c1.Apelido) AS clienteB, s.Documento,
t.Pasta, t.Livro, t.Folhas
FROM atos_has_servicos AS t
INNER JOIN atos AS t1 ON(t.atos_idAtos = t1.idAtos)
INNER JOIN contactos AS c ON (t1.idContacto1 = c.idcontactos)
INNER JOIN contactos AS c1 ON (t1.idContactos2 = c1.idcontactos)
INNER JOIN servicos AS s ON (t.Servicos_idServicos = s.idServicos)
WHERE t1.idAtos = :idAtos;


And when i'm try to put this into HQL
Code:
SELECT a.pasta, a.livro, at.dataAto, s.documento FROM AtosHasServicos a JOIN a.atos at JOIN a.servicos s join at.contactos c


i have the following error

Caused by: org.hibernate.QueryException: could not resolve property: contactos of: model.Atos

But Model "Atos" has this property

Code:
@JoinColumn(name = "idContacto1", referencedColumnName = "idcontactos")
    @ManyToOne(optional = false)
    private Contactos idContacto1;
    @JoinColumn(name = "idContactos2", referencedColumnName = "idcontactos")
    @ManyToOne(optional = false)
    private Contactos idContactos2;


And "Contactos" model

Code:
@OneToMany(cascade = CascadeType.ALL, mappedBy = "idContacto1")
    private Set<Atos> atosSet;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idContactos2")
    private Set<Atos> atosSet1;



any help?


Top
 Profile  
 
 Post subject: Re: HQL problem
PostPosted: Fri Nov 17, 2017 2:38 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
Quote:
But Model "Atos" has this property


No, it does not.

The property name must match exactly. You want to join "at.contactos", but the property is called:

- idContacto1
- idContacto2

So, either one of this would be valid:

- join at.idContacto1 c1
- join at.idContacto2 c2


Top
 Profile  
 
 Post subject: Re: HQL problem
PostPosted: Fri Nov 17, 2017 7:35 am 
Newbie

Joined: Thu Nov 16, 2017 7:16 pm
Posts: 3
Thank you

It worked...

I still have to learn a lot.

Best regards


Top
 Profile  
 
 Post subject: Re: HQL problem
PostPosted: Fri Nov 17, 2017 8:05 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
These 200 tutorials about JPA and Hibernate will surely help you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.