jpql

Selecting an entity by collection set equality

99封情书 提交于 2019-12-24 00:55:47
问题 I'm trying to do a JPQL query or JPA operation that does the following. I have an element, that consist of an element collection of Strings: @Entity(name="REQUEST") public class Request { @ElementCollection private Set<String> keywords; ... } I want to be able to select the entity whos keywords exactly matches a given Set of strings. I've looked into using IN but that will match if only one keyword exists. How do I match only if all keywords exist? 回答1: The simplest approach I can think of is

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

How to select the sum of multiple count() selections in JPQL

穿精又带淫゛_ 提交于 2019-12-23 15:59:58
问题 What's the equivalent JQPL statement of the following SQL statement: SELECT (SELECT COUNT(*) FROM foo) + (SELECT COUNT(*) FROM bar) 回答1: You can use the query you stated above along with EntityManager's createNativeQuery function see example class below: package facades; import javax.ejb.LocalBean; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.Query; @Stateless @LocalBean public class CustomFacade {

Java EE/JPA way to add new tables/entities to database

别等时光非礼了梦想. 提交于 2019-12-23 12:16:56
问题 I have a mysql database that I want to add the functionality of adding a new table to the database. I could probably easily find the example of the JPQL for this but how would I then automatically generate the entity for this new table so that I could reference it in the rest of my JPA code for updating and deleting from the table I usually reference the entity not the actual table itself. The Entities I have now I've used eclipe to generate from the tables I created. But after deployment we

In JPA 2.0 JPQL, when one returns a NEW object, how may one make use of FETCH JOINs?

别等时光非礼了梦想. 提交于 2019-12-23 09:59:49
问题 A colleague of mine has the following (apparently invalid) JPQL query: SELECT NEW com.foobar.jpa.DonationAllocationDTOEntity(a.id, a.campaign, a.campAppeal, a.campDivision, a.divisionFund) FROM DonationAllocation a JOIN a.donation d JOIN a.allocationType t JOIN FETCH a.campaign WHERE d.id = :donationId AND (t.code = 'Pledge' OR t.code = 'MatchingPledge') It is worth noting (for later in this message) that DonationAllocation 's relationship with a Campaign entity is many-to-one, and is marked

Insert to JPA collection without loading it

醉酒当歌 提交于 2019-12-23 09:19:32
问题 I'm currently using code like this to add a new entry to a set in my entity. player = em.find(Player.class, playerId); player.getAvatarAttributeOwnership().add(new AvatarAttributeOwnership(...)); It works, but every time I want to add one item, the whole set is loaded. Is there a way (with a query maybe) to add the item without loading the rest? In SQL it would be something like INSERT INTO AvatarAttributeOwnership(player, data, ...) VALUES({player}, ...); Currently uniqueness is maintained

Refactor native query to JPQL query

南笙酒味 提交于 2019-12-23 05:25:12
问题 Suppose we have the following table, named as 'documents': id | createDate | createBy | updateDate | updateBy -------------------------------------------------- (various rows here) the two *date columns are timestamps while the other are all strings (even the id ) Currently I have the following native query used in a Spring Repository: select COUNT(distinct(u.user_working_total)) from ( select distinct(createBy) user_working_total from documents where createDate >= :startDate and createDate <

How to improve performance of Updating data using JPA

三世轮回 提交于 2019-12-23 05:09:04
问题 I am using EJB and Container managed EM ( for local testing I am creating em here). I have a requirement where I need to update database based on some condition, My issue is Update is taking very long time , how to reduce it ? I tried two approach 1> Update Query 2> Update in entity Please let me know if I am doing any mistake, or any other approach exist. Note : code for update is below public class Test { private static final int OaOnaccount = 0; private static final int ArrayList = 0;

Find entity filtered by a related entity that is in a collection

僤鯓⒐⒋嵵緔 提交于 2019-12-23 04:33:51
问题 I'm using Spring Data JPA for my repository layer and spring security as my security layer. In my project, I have the following unidirectional one-to-many relationship between Department and Employee. Below are snippets of the 2 entities. @Entity public class Department { ... @OneToMany @JoinColumn(name="department") private Set<Employee> members; ... } @Entity public class Employee { ... private String username; ... } The relationship has to be unidirectional due to certain restrictions and

Kundera Cassandra JPQL with Compound Key

ε祈祈猫儿з 提交于 2019-12-23 04:18:16
问题 Am using Kundera JPA for Cassandra. Kundera version is: 3.8 Here are my Entity definitions:- @Embeddable public class PartitionKey implements Serializable { @Column(name = "ID") private String Id; @Column (name = "TYPE") private String Type; } @Embeddable public class CompoundKey implements Serializable { @Embedded private PartitionKey partitionKey; @Column(name = "LABEL") private String label; } @Embeddable public class Comment { @Column(name="comment") private String comment; } @Entity