jpa-2.1

JPA 2.1 Create entity within JPA EntityListener

你说的曾经没有我的故事 提交于 2021-01-28 14:54:45
问题 I try to create a log entry as soon as one of my entities got changed or created. In order to do this, I registered an EntityListener on an AbstractEntity class. AbstractEntity has a List of LogEntries and the cascade type of this list is ALL (all of my entities inherits from AbstractEntity). Current implementation of my EntityListener: public class EntityChangeListener { @Inject SessionController sessionController; @PreUpdate public void preUpdate(AbstractEntity entity) { createLogEntryFor

JPA 2.1 Create entity within JPA EntityListener

百般思念 提交于 2021-01-28 14:42:56
问题 I try to create a log entry as soon as one of my entities got changed or created. In order to do this, I registered an EntityListener on an AbstractEntity class. AbstractEntity has a List of LogEntries and the cascade type of this list is ALL (all of my entities inherits from AbstractEntity). Current implementation of my EntityListener: public class EntityChangeListener { @Inject SessionController sessionController; @PreUpdate public void preUpdate(AbstractEntity entity) { createLogEntryFor

Navigation method/s in criteria fetch joins in JPA 2.1

江枫思渺然 提交于 2021-01-27 17:10:48
问题 While using fetch joins in JPA criteria, there is no navigation method can be seen. Given below an example. Root<UserTable> root = criteriaQuery.from(entityManager.getMetamodel().entity(UserTable.class)); Fetch<UserTable, StateTable> fetch = root.fetch(UserTable_.stateTable, JoinType.INNER); To navigate through the entity in question, this Fetch type is required to be cast to a join like as follows. Join<UserTable, StateTable> join = (Join<UserTable, StateTable>) root.fetch(UserTable_

org.eclipse.persistence.indirection.IndirectMap cannot be cast to org.eclipse.persistence.queries.FetchGroupTracker using EclipseLink

﹥>﹥吖頭↗ 提交于 2020-12-15 04:55:33
问题 I have the following design: One sports game has two scores (one per team) and each score has multiple player stats, one per jersey number. Both relationships are mapped as Map . This is just multi-level aggregation. Game entity: @Entity @Table(name = "\"Games\"") @NamedQuery(name = Game.FIND_ALL, query = "SELECT ga FROM Game ga") @NamedEntityGraph(name = Game.FETCH_SCORES, attributeNodes = {@NamedAttributeNode("scores")}) @NamedEntityGraph(name = Game.FETCH_SCORES_AND_PLAYER_STATS,

EclipseLink query exceptions using EntityGraph: “You must define a fetch group manager at descriptor” AND “Fetch group cannot be set on report query”

爱⌒轻易说出口 提交于 2020-06-29 03:53:00
问题 I have the following design: For reference, I'm only posting the SimpleGame entity: @Entity @Table(name = "\"SimpleGames\"") @NamedQuery(name = SimpleGame.FIND_ALL, query = "SELECT ga FROM SimpleGame ga") @NamedQuery(name = SimpleGame.FIND_ALL_JOIN_SCORES_GROUP_BY_GAME_ID, query = "SELECT ga FROM SimpleGame ga JOIN ga.simpleScores sc GROUP BY ga.id") @NamedEntityGraph(name = SimpleGame.FETCH_SCORES, attributeNodes = {@NamedAttributeNode("simpleScores")}) public class SimpleGame implements

EclipseLink query exceptions using EntityGraph: “You must define a fetch group manager at descriptor” AND “Fetch group cannot be set on report query”

前提是你 提交于 2020-06-29 03:52:33
问题 I have the following design: For reference, I'm only posting the SimpleGame entity: @Entity @Table(name = "\"SimpleGames\"") @NamedQuery(name = SimpleGame.FIND_ALL, query = "SELECT ga FROM SimpleGame ga") @NamedQuery(name = SimpleGame.FIND_ALL_JOIN_SCORES_GROUP_BY_GAME_ID, query = "SELECT ga FROM SimpleGame ga JOIN ga.simpleScores sc GROUP BY ga.id") @NamedEntityGraph(name = SimpleGame.FETCH_SCORES, attributeNodes = {@NamedAttributeNode("simpleScores")}) public class SimpleGame implements

Why does spring jpa ignore javax.persistence.FetchType.LAZY and javax.persistence.NamedEntityGraph?

做~自己de王妃 提交于 2020-06-17 09:40:30
问题 I have a basic "Department"/"Employee" example. Full example here (in master branch) : https://github.com/granadacoder/jpa-simple-example-one.git If you setup 4 environment variables (listed in the README), the code is runnable/debuggable. For my "findAll()" method, I am trying to only bring back the scalars of the Department entity. (key and name). Aka, I do NOT want any child Employees to be tacked onto the Department .. when I do a findAll(). I have tried using an name EntityGraph, but it

Outer joins with ON conditions in JPA

谁说胖子不能爱 提交于 2020-01-25 01:00:09
问题 I need a criteria query for the following SQL query. SELECT w.weight_id, w.weight, zc.charge FROM weight w LEFT OUTER JOIN zone_charge zc ON w.weight_id=zc.weight_id AND zc.zone_id=? <------- ORDER BY w.weight ASC The corresponding JPQL query would be like, SELECT w.weightId, w.weight, zc.charge FROM Weight w LEFT JOIN w.zoneChargeSet zc WITH zc.zone.zoneId=:id <------- ORDER BY w.weight I can't reproduce the same with criteria especially WITH zc.zone.zoneId=:id . The following criteria query

Set timeout on a TypedQuery with JPA2

时间秒杀一切 提交于 2020-01-06 06:47:14
问题 I would like to set a timeout on a javax.persistence.TypedQuery. I've found this easy method : TypedQuery<Foo> query = ... ; query.setHint("javax.persistence.query.timeout", 1000); query.getReturnList(); But it seems that does not work, it's just ignored. From the PRO JPA 2 book: "Unfortunately, setting a query timeout is not portable behavior. It may not be supported by all database platforms nor is it a requirement to be supported by all persistence providers. Therefore, applications that

Sub-Query in Spring Data Jpa

谁说胖子不能爱 提交于 2020-01-06 01:30:32
问题 I have query like this in jpql select new com.example.CustomGroup(m.id, m.title, (select count(w.id) from MessageGroup x join x.messages w where w.readers.id <> ?1) ) from MessageGroup m join m.members u where u.id = ?1 but not work, i know jpa 2 support sub query in select but cant find any refrence to how use it 回答1: Quote from the JPA 2.2 specification, paragraph 4.6.16: Subqueries may be used in the WHERE or HAVING clause.[66] [66] Subqueries are restricted to the WHERE and HAVING clauses