1
I am using the Eclipselink implementation and cannot solve the following query
that must be wrong:
Query query = em.createQuery("SELECT e , COUNT(*) FROM Empregado e");
Integer resultado = (Integer) query.getSingleResult();
My entyties
sane:
public class Empregado implements Serializable {
@Id
@GeneratedValue
private int id;
private String nome;
private int idade;
@OneToOne(cascade = CascadeType.ALL)
private Telefone telefone;
.... getters and setters
And this:
@Entity
public class Telefone {
@Id
@GeneratedValue
private int id;
private String numero;
private String tipo;
.... getters and setters
The following error occurs:
Exception in thread "main" java.lang.Illegalargumentexception: An Exception occurred while Creating a query in Entitymanager:
Exception Description: Syntax error Parsing [SELECT e , COUNT(*) FROM Employee e]. [16, 16] The left Expression is Missing from the arithmetic Expression. [17, 17] The right Expression is Missing from the arithmetic Expression
I would like to know if possible how to do the query
and also how to achieve the same result using the new features of the JPA 2.1 the famous Stored Procedure Query
.
I already searched and found some examples that received a parameter for the function but in my case and I do not pass nor a parameter I just want the result!
Here is the link in English from the example, which receives a parameter in the stored procedure.
What mistake are you making? Try it this way:
SELECT COUNT(*) FROM Empregado e
– Ricardo
I tried that! It didn’t work, jpa doesn’t recognize the *
– Pena Pintada