Hi. I'm using JPA annotations, EntityManager, and JPA metamodel to create typed queries. Note the
from null part in the query below; I get a QuerySyntaxException due to the fact that my code is generating the following SQL/HQL/JP-QL (not sure which, but it's probably supposed to be one of the latter two):
Code:
select generatedAlias0 from null as generatedAlias0 where generatedAlias0.playerId=:param0]
This is the code I'm using to generate it:
Code:
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Player> criteriaQuery = criteriaBuilder.createQuery(Player.class);
Root<Player> root = criteriaQuery.from(Player.class);
Predicate condition = criteriaBuilder.equal(root.get(Player_.playerId), player.getPlayerId());
criteriaQuery.where(condition);
TypedQuery<Player> typedQuery = entityManager.createQuery(criteriaQuery);
Player result = typedQuery.getSingleResult();
Even when I put in the following line (though I'm not sure it's even necessary), nothing changes:
Code:
criteria.select( root );
Here is my entity:
Code:
@Entity
@Table(name = "players",
uniqueConstraints = {@UniqueConstraint(columnNames={"playerId"})}
)
public class Player implements java.io.Serializable {
@Id @GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@Column(nullable = false) private String fullName;
@Column(nullable = false) private String playerId;
private Date birthdate;
// more code here ...
}
Has anyone seen this sort of behavior before, and/or know what I need to do to fix it? Thanks very much!