0%

Recently, I faced up a problem in my project. I tried to use generic type in my project, but when it came to the hibernate hql, I can not get the generic type. Following is the solution:

Let’s begin

Step 1:

Suppose I have a normal class like findById.

1
2
3
4
5
6
7
8
@Override
public User findById(Long id) {
String hql = "FROM User u where u.id = :userId";
Session s = sessionFactory.getCurrentSession();
TypedQuery<User> query = s.createQuery(hql);
query.setParameter("userId", id);
return query.getSingleResult();
}
Read more »

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

blue test block
purple test block
yellow test block
green test block

Download Now

awesome pencil icon test

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Read more »