I’m having some problems with my HQL query. I want to get 10 posts from the database using Hibernate.
My mapping:
@Entity
@Table(name = "bl_post", uniqueConstraints = {
@UniqueConstraint(columnNames = "post_id"),
@UniqueConstraint(columnNames = "post_text"),
@UniqueConstraint(columnNames = "user_id"),
@UniqueConstraint(columnNames = "datePub")
})
public class Post implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column( name = "post_id", unique = true, nullable = false)
private Long postId;
@Transient
private ObjectStatus statusPost;
@Column(name = "post_title", length = 255)
private String title;
@Column(name = "post_text", unique = true, nullable = false, length = 25000)
private String text;
@JoinColumn(name = "user_id", unique = true, nullable = false)
@OneToOne(cascade = CascadeType.ALL)
private User user;
// @XmlJavaTypeAdapter(value = LocalDateAdapter.class)
@Column(name = "datePub", unique = true, nullable = false)
private LocalDateTime dateOfPublish;
@Transient
private List<Comment> postComments;
public Post() {
}
My query is:
TypedQuery<Post> query = em.createQuery(
"FROM Post p ORDER BY p.datePub DESC", Post.class);
query.setMaxResults(10);
posts = query.getResultList();
And the error that it throws is:
Caused by: org.hibernate.QueryException: could not resolve property: datePub of: service.domian.Post
(domian is the spelling I use elsewhere, that is not a typo)
I have made double certain that there no typos that I can find. I also tried changing the names, etc. This must be something very obvious but I just can’t see it.
New contributor
Pawel Arol is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.