jpql

jpa, risks of using an illegal named query?

大城市里の小女人 提交于 2019-12-11 14:42:22
问题 I made a NamedQuery that works but I have multiple error markers in eclipse. Now my query might not be legal, an answer of so (see comments) told me it wasn't possible to do what I intended to do in jpa. So, since I managed to do it anyway and I don't really have a clue why it works: my question is what are the underlying risks of using this : query = "SELECT t FROM Thethread t LEFT JOIN FETCH t.threadVotes tv ON tv.user1=:currentUser ORDER BY t.datePosted DESC" Under on: JOIN FETCH

Error using CURRENT_TIMESTAMP() into a query

主宰稳场 提交于 2019-12-11 14:35:44
问题 I want to compare two date in jpql query using the current date function I got an error Syntax error parsing [SELECT d FROM Dossier d WHERE d.depid=1 AND d.typeDossier = :tpd AND d.dateCreation < CURRENT_TIMESTAMP() + 5]. [105, 107] The left expression is not an arithmetic expression This is my query: public List<Dossier> getDossierFindAllParDepartementDBTECHandUrgen() { return (List<Dossier>) em.createQuery("SELECT d FROM Dossier d WHERE d.depid=1 AND d.typeDossier = :tpd AND " + "d

Retrieving data from native query and conversion

筅森魡賤 提交于 2019-12-11 13:29:14
问题 I have following query @Override public List<PlayerDetails> testPlayerQuerry() { return copyPlayersToDetails(em.createNativeQuery("select player_name from player p\n" + "join Player_Game pg on p.player_id = pg.fk_player_id\n" + "join Game g on pg.fk_game_id = g.game_id\n" + "where g.game_id = 2").getResultList()); } which as far as I am aware it return list of String? due to the error I am getting Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to entities.Player at

Issue when trying to use the IN operator in a JPQL query

◇◆丶佛笑我妖孽 提交于 2019-12-11 13:15:01
问题 the following query : SELECT P FROM Project P WHERE :currentUser IN(P.assignedUsers) throws the following error : org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement: "...."; expected "NOT, EXISTS, INTERSECTS, SELECT, FROM"; Am i using the IN operator wrong, or am i supposed to do it differently. Project.assignedUsers : is a list containing users (a OneToMany Relationship). and the currentUser parameter is a valid user. 回答1: You cannot use implicit joins for this purpose; you probably

How to continuously remove anything older than the newst 10 entries of a MySQLdatabase (Possibly in JPQL/JPA)

牧云@^-^@ 提交于 2019-12-11 13:14:26
问题 I'm looking for a way to continuously monitor and delete the oldest entries so that the database is never larger than a certain value. I'm only interested in the latest 10 for example and everything past that number should be deleted. The database is updated through varous programs but the program that does the monitoring and deleting will probably be a Java EE application with JPA. I don't know at which layer of the implementation this will be done. If MySQL has build in management that does

JPQL Query Bulk UPDATE SET on an ElementCollection field

浪尽此生 提交于 2019-12-11 12:09:45
问题 I have the following JPA Entity I want to update: @Entity(name = "EmployeeImpl") @Table(name = "EmployeeImpl") public class EmployeeImpl { @Id @Column(name = "employeeId") @GeneratedValue(strategy = GenerationType.AUTO) private long id; @ElementCollection private List<String> phonenumber; } I thought I use a namedQuery like so @NamedQuery(name = "updateEmployee", query = "Update EmployeeImpl e SET e.phonenumber :number WHERE e.id = :id") But that doesn't work: Exception Description: Error

Issue rendering JPQL custom query results into a JSF page

此生再无相见时 提交于 2019-12-11 10:56:29
问题 I have an entity with the following named query: @NamedQuery(name = "findAllGarbage", query = "SELECT g.filename, g.description, g.uploadDate FROM Garbage g;") The problem is that i want to pass that result to a dataTable to render, and i recieve NumberFormatException. I dont understand why because there are no numbers anywhere. This is how the rest of the program looks like: -The EJB that executes the query @Stateless(name = "ejbs/SearchEJB") public class SearchEJB implements ISearchEJB {

JPQL+ MYSQL to get rid of `You can't specify target table XXX for update in FROM clause`

谁说胖子不能爱 提交于 2019-12-11 09:46:16
问题 There is an AccessLog table which logs which user (FK user_id ) accesses which mail (FK mail_id ) at which time(column created ). The table grows as time goes by. I want to keep the latest row (which user last accesses which mail) , removing all old logs. The following SQL code works as expected: delete from AccessLog where id not in ( select id from ( select a.id from AccessLog a where a.created = (select max(b.created) from AccessLog b where b.user_id = a.user_id and b.mail_id = a.mail_id )

JPQL count Parent Objects on Multiple Children Match in OneToMany Relationship

流过昼夜 提交于 2019-12-11 08:09:53
问题 In a JavaEE JPA web application, Feature entity has bidirectional ManyToOne relationship with Patient Entity. I want to write a query to count the number of Patients who have one or more matching criteria features. I use EclipseLink as the Persistence Provider. For example, I want to count the number of patients who have a feature with 'variableName' = 'Sex' and 'variableData' = 'Female' and another feature with 'variableName' = 'smoking' and 'variableData' = 'yes'. How can I write a JPQL

Spring Boot JPA “Validation failed for query” error for JPQL

[亡魂溺海] 提交于 2019-12-11 07:28:21
问题 I'm trying use a custom query with jpa (not a nativeQuery since I want to map the result to a custom object) and I can't figure out whats wrong. The repository class looks like this: @Repository public interface ChallengeCompletionRepository extends JpaRepository<ChallengeCompletion, Integer>{ List<ChallengeCompletion> findByUser(int uid); List<ChallengeCompletion> findByChallenge(int cid); List<ChallengeCompletion> findByUserAndChallenge(int uid, int cid); @Query(value = "SELECT new com.some