Typical named sleep request primary

Are named queries supported by default in Hibernate version 4.2.3.Final? I get this exception with one:

java.lang.ArrayIndexOutOfBoundsException: 0 at org.hibernate.ejb.AbstractEntityManagerImpl.createNamedQuery(AbstractEntityManagerImpl.java:637) at sun.reflect.GeneratedMethodAccessor23.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:241) at $Proxy78.createNamedQuery(Unknown Source) 

When I execute this query using the Query class, everything is fine. TypedQuery seems to be a problem here, and the exception is not very useful. I tried this with simple queries to very complex queries, and all of them seem to fail if I didn't use Query for the named main query.

+6
source share
2 answers

You can specify SqlResultSetMapping to get rid of this error. For instance:

 @javax.persistence.Entity @javax.persistence.SqlResultSetMapping( name = "implicit", entities = @javax.persistence.EntityResult(entityClass = Account.class) ) @javax.persistence.NamedNativeQuery( name = "findAccount", query = "SELECT a.* FROM account a WHERE a.account_id=?1", resultSetMapping = "implicit") public class Account implements java.io.Serializable { [...] } 

Thus, Hibernate knows how to handle the values ​​returned by the original request.

+8
source

I had this problem when I moved the HQL query code from the code to the mapping file, but accidentally put it in an element instead of a.

But yes, this is not a very useful message.

0
source

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


All Articles