jpa-2.0

Hibernate JPQL - querying for KEY() in Map association error

佐手、 提交于 2019-12-23 17:30:25
问题 I'm trying to make a JPQL query that should fetch an entity and the keys from one of its map associations, and I'm getting a bizzare error. My setup is JPA2 using the Hibernate (3.5) implementation. The model is as follows: I have a Department entity bean such as: @Entity public class Department { @Id @SequenceGenerator(name = "DEPARTMENT_ID_GENERATOR", sequenceName="department_sequence", allocationSize=100) @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "DEPARTMENT_ID

JPA: Selecting entities based on multiple criterions on multiple child entities

感情迁移 提交于 2019-12-23 17:21:30
问题 I have a problem getting the following scenario to work. A student can take tests. A student have over time taken a few tests and got a score for each test. Each student entity have a list of tests that they have completed mapped as @OneToMany. Now I want to select all students that have completed tests on a range of grouped criterions. I want for example to search for all students that have: Group 1: Completed "Test 1" and got a score "between 75 and 100" and/or Group 2: Completed "Test 2"

What is the difference between CacheStoreMode USE and REFRESH

瘦欲@ 提交于 2019-12-23 17:17:46
问题 The javadocs for CacheStoreMode differentiate in a point I cannot really grasp: The javadocs for the USE mode: Insert/update entity data into cache when read from database and when committed into database: this is the default behavior. Does not force refresh of already cached items when reading from database. The javadocs for the REFRESH mode differ in the last sentence: Forces refresh of cache for items read from database. When an existing cached entity instance is updated when reading from

What is the difference between CacheStoreMode USE and REFRESH

我与影子孤独终老i 提交于 2019-12-23 17:13:08
问题 The javadocs for CacheStoreMode differentiate in a point I cannot really grasp: The javadocs for the USE mode: Insert/update entity data into cache when read from database and when committed into database: this is the default behavior. Does not force refresh of already cached items when reading from database. The javadocs for the REFRESH mode differ in the last sentence: Forces refresh of cache for items read from database. When an existing cached entity instance is updated when reading from

EclipseLink JPA: Can I run multiple queries from one builder?

倖福魔咒の 提交于 2019-12-23 13:13:15
问题 I have a method that builds and runs a Criteria query. The query does what I want it to, specifically it filters (and sorts) records based on user input. Also, the query size is restricted to the number of records on the screen. This is important because the data table can be potentially very large. However, if filters are applied, I want to count the number of records that would be returned if the query was not limited. So this means running two queries: one to fetch the records and then one

How to store uuid in binary form using hibernate JPA 2

旧巷老猫 提交于 2019-12-23 12:09:49
问题 I have a question about string uuid in database in binary form through hibernate persistence (JPA2). I'm using now this code: private UUID id; @Id @Type(type="uuid-char") @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") @Column(length = 32, unique = true, nullable = false) public final UUID getId() { return id; } This work fine, but I must store it in binary form. Don't ask me why, but I must. 回答1: The type for binary UUID is uuid-binary .

Differences between Container Managed and Application Managed EntityManager

坚强是说给别人听的谎言 提交于 2019-12-23 10:55:39
问题 I have a problem to understand the differences between container-managed and application-managed entity manager? I would be very grateful if you can give me an example that illustrates the differences. 回答1: For a container-managed entity manager, the container manages the life-cycle of this entity manager. For an application-managed one, the application (meaning you, the programmer) manages this. A simple but very visible difference is that you must call close() on an application-managed

Where can i find jpa orm.xml usage samples [closed]

微笑、不失礼 提交于 2019-12-23 07:42:02
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I am trying to see some usage samples of JPA orm.xml. If some one direct me to a link, 回答1: The schema is here, http://java.sun.com/xml/ns/persistence/orm_2_0.xsd There are lots of samples of each mapping type here, http://en.wikibooks.org/wiki/Java_Persistence Lots of examples here, http://wiki.eclipse.org

jpa criteria-api: join with subselect

一笑奈何 提交于 2019-12-23 07:36:13
问题 This query is used to retrieve last records in a one-to-many relationship (see SQL join: selecting the last records in a one-to-many relationship) SELECT p.* FROM customer c INNER JOIN ( SELECT customer_id, MAX(date) MaxDate FROM purchase GROUP BY customer_id ) MaxDates ON c.id = MaxDates.customer_id INNER JOIN purchase p ON MaxDates.customer_id = p.customer_id AND MaxDates.MaxDate = p.date; My question: How can I build this join with the subselect with the jpa criteria-api? Is it possible?

Set selection of typesafe JPA 2 query with joins

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 05:06:54
问题 I have simple query with two joins: SELECT p.id, BU.ID, BU.TEXTLANG as Title FROM PROJEKT P JOIN Text BT ON BT.ID = P.TITEL_ID JOIN Uebersetzung BU ON BU.TEXT_ID = BT.ID WHERE BU.TEXTLANG LIKE '%Spatial%'; This query must be converted to a typesafe query, what i tried is: final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); final CriteriaQuery<Projekt> query = criteriaBuilder.createQuery(Projekt.class); final Root<Projekt> projekt = query.from(Projekt.class); Join