I have two tables TUser and TComment, relation 1 to many. I want to write a Hibernate query which extract unique TUsers which did comments.
I tried:
EntityManager em = HibernateUtil.getEntityManager();
Query queryCommentsAuthors = em.createQuery("select u.author from TComment u group by u.author");
Error:
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: java.sql.SQLException: ORA-00979: not a GROUP BY expression
and this:
Query queryCommentsAuthors = em.createQuery("select distinct u.author from TComment");
Error:
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: java.sql.SQLException: ORA-00932: inconsistent datatypes: expected - got BLOB
But without success. I appreciate any advices to cope with this problem.
Here is the part of my bean class where i have TUser object:
@Entity
@Table(name = "T_COMMENT")
public class TComment implements java.io.Serializable {
private TUser author;
....
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "AUTHOR_ID", nullable = false)
public TUser getAuthor() {
return this.author;
}
public void setAuthor(TUser author) {
this.author = author;
}
.....
}
This is the DDL of the table:
create table T_COMMENT
(
id NUMBER(19) not null,
comment_body VARCHAR2(4000 CHAR) not null,
comment_date DATE not null,
author_id NUMBER(19) not null,
)