I have this class:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "tipo", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue(value = "")
@Table(name = "publicacao")
@NamedQuery(name = "findPubOrderByAutor", query = "SELECT publicacao FROM Publicacao pub JOIN pub.autores a WHERE a.id = :id ORDER BY pub.autores")})
public abstract class Publicacao {
@Column(name = "autores", nullable = false)
@ManyToMany(fetch = FetchType.EAGER)
@OrderBy("nome")
@JoinTable(name = "pub_autor",
joinColumns = @JoinColumn(name = "autor_id"),
inverseJoinColumns = @JoinColumn(name = "publicacao_id"))
private List<Autor> autores;
}
And I am getting this Error:
java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.IdentNode
-[IDENT] IdentNode: ''Publicacao'' {originalText=Publicacao}
For that NamedQuery in the class
"SELECT publicacao FROM Publicacao pub JOIN pub.autores a WHERE a.id = :id ORDER BY pub.autores"
If I replace publicacao for Publicacao I get the same error but for ...''publicacao''...
Java 7 Hibernate 3.5.5 JPA 2.0 (I think)
Please let me know if I missed some importante information.
I don't know what to do since it points me the same error both for the table and the object name.
Thanks in advance.
ORDER BY pub.autores
This is probably the reason of the exception. Ordering by a collection doesn't make sense.
Another problem is
SELECT publicacao
publicacao
is not an alias defined in the query. You should use select pub
instead.
Also, you shouldn't have the @Column
annotation on autores
. It's a ManyToMany association, and is thus not mapped as a column. And you also use inverseJoinColumns
where you should use joinColumns
, and vice-versa.
I think the problem is only due to use of undefined alias. Instead of writing SELECT publicacao
write SELECT pub
.
After change code will look this,
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "tipo", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue(value = "")
@Table(name = "publicacao")
@NamedQuery(name = "findPubOrderByAutor", query = "SELECT pub FROM Publicacao pub JOIN pub.autores a WHERE a.id = :id ORDER BY pub.autores")})
public abstract class Publicacao {
@Column(name = "autores", nullable = false)
@ManyToMany(fetch = FetchType.EAGER)
@OrderBy("nome")
@JoinTable(name = "pub_autor", joinColumns = @JoinColumn(name = "autor_id"), inverseJoinColumns = @JoinColumn(name = "publicacao_id"))
private List<Autor> autores;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.