no viable alternative at input 'SELECT*' – Java

by
Ali Hasan
entity-framework-core hibernate postgresql spring-boot

Quick Fix: Resolve ‘no viable alternative at input ‘SELECT* error by using entity and attribute names with positional parameters. Update your code as shown, ensuring to use TypedQuery and set parameters:

The Problem:

While formulating a PostgreSQL query using Hibernate’s EntityManager, the user encountered an error stating ‘no viable alternative at input ‘SELECT*’.’ This error occurred when attempting to create a TypedQuery using the ‘createQuery’ method. The query in question is ‘SELECT * FROM user_details where user_name = ? LIMIT 1’, which is valid and works correctly when executed directly in a SQL console. The code snippet provided indicates that the query is defined as a static final String and then used to construct a TypedQuery, with a parameter for ‘user_name’. Despite this setup, the error persists.

Q&A

What Caused Error No viable alternative at input ‘SELECT*’ ?

Using a native SQL query in JPA with Hibernate.

How to fix error no viable alternative at input ‘SELECT*’ ?

Use entity and attribute names along with positional parameters.

Video Explanation:

The following video, titled "How to Fix this Project Already Has Another Free Cluster | MongoDB ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

What's up yall, in this video I'm showing you how to fix this little error that appears when you try to create a cluster in mongoDB #mongodb ...