Basically I’m querying a table like the following
keywordId | keyword
1 abc
1 abcd
2 feg
2 xyz
2 tuv
When I pass a query such as:
"FROM keyword Where keywordId = 2"
I get back the following:
2 feg
2 feg
2 feg
Here’s the method I’m using
public List<DataModel> selectRecord(String sqlQuery) {
SessionFactory factory = new Configuration().configure().buildSessionFactory();
Session session = factory.openSession();
session.beginTransaction();
Query query = session.createQuery(sqlQuery);
List<DataModel> data = query.list();
session.clear();
session.close();
return data;
}
Honestly not too sure why this is happening, but it’s also occuring in other tables with the same structure may FK’s
Insight appreciated! 🙂
Main reason for this is that their is no identifier property in your database. Hibernate is not capable of understanding and that
is different from the below one.
Best practice would be to define a primary key for the table. You can find more about this issue by visiting this link.Hope this helps