Select one column from a row in sleep mode

I am trying to make a simple query to get a unique result in hibernate, here is my code.

public String getName(Integer id) { Session session = getSessionFactory().openSession(); String name = (String)session.createSQLQuery("SELECT name FROM users WHERE user_id = :userId").setParameter("userId", id).uniqueResult(); return name; } 

The return name is saved as HTML text, which includes the html syntax language. I think this is what causes the problem, but it does not make sense. I just want to return it as a string.

This only happens in this name of one field, I can get every other field in the string, but it gives me an error.

I get an exception. The exception that I get is

No dialect display for JDBC type: -1; Nested Exception - org.hibernate.HibernateException

How do you query a specific column in a row in sleep mode?

+4
source share
2 answers

I understood the solution, it is obvious that Java does not have a type that can be displayed in text fields, so you need to add a scalar solution below: Thanks for the help

 session.createSQLQuery("SELECT name FROM users WHERE user_id = :userId").addScalar("name", Hibernate.TEXT).setParameter("userId", id).uniqueResult(); 
+2
source

Then it should work. Use Type Sleep Annotation.

Add

 @Type(type="text") 

To your image.

0
source

Source: https://habr.com/ru/post/1339360/


All Articles