jpql

Update Entity Relationship via UPDATE .. SET Query

∥☆過路亽.° 提交于 2020-01-25 07:37:05
问题 I have two entities: class A { @OneToMany(mappedBy = "a") List<B> bs; // getter/ setter } class B { @ManyToOne A a; // getter/ setter } To delete one b, I first need to invalidate that relationship. "Traditionally" I would do something like that: A a = em.getReference(A.class, entityIdA) B b = em.getReference(B.class, entityIdB); a.getBs().remove(b); b.setA(null); em.remove(b); This is not very performant, if the List of a 's is getting large (a few hundreds in my case). I know I can also use

JPA - using long array in IN operator throws cast exception

匆匆过客 提交于 2020-01-23 13:13:10
问题 am new to JPA and am able to get it quickly, I had been trying a select query using "IN" operator in the query and had been getting the error as down. What I do is, i get a array of (long) message ids from a function and i use it to select the record based on those ids. Here is my query select t from MessageTable t where t.messageId IN (:id) query.setParameter("id", id); I had just shown you part of the code, in entity messageId is long and in Oracle DB its number. When i try as just as long

Multiple JOIN FETCH in one JPQL query

元气小坏坏 提交于 2020-01-20 16:10:28
问题 I have below entities: public class Category { private Integer id; @OneToMany(mappedBy = "parent") private List<Topic> topics; } public class Topic { private Integer id; @OneToMany(mappedBy = "parent") private List<Posts> posts; @ManyToOne @JoinColumn(name = "id") private Category parent; } public class Post { private Integer id; @ManyToOne @JoinColumn(name = "id") private Topic parent; /* Post fields */ } and I want fetch all categories with joined topics and joined posts using JPQL query. I

Multiple JOIN FETCH in one JPQL query

北城以北 提交于 2020-01-20 16:06:39
问题 I have below entities: public class Category { private Integer id; @OneToMany(mappedBy = "parent") private List<Topic> topics; } public class Topic { private Integer id; @OneToMany(mappedBy = "parent") private List<Posts> posts; @ManyToOne @JoinColumn(name = "id") private Category parent; } public class Post { private Integer id; @ManyToOne @JoinColumn(name = "id") private Topic parent; /* Post fields */ } and I want fetch all categories with joined topics and joined posts using JPQL query. I

Multiple JOIN FETCH in one JPQL query

自作多情 提交于 2020-01-20 16:04:42
问题 I have below entities: public class Category { private Integer id; @OneToMany(mappedBy = "parent") private List<Topic> topics; } public class Topic { private Integer id; @OneToMany(mappedBy = "parent") private List<Posts> posts; @ManyToOne @JoinColumn(name = "id") private Category parent; } public class Post { private Integer id; @ManyToOne @JoinColumn(name = "id") private Topic parent; /* Post fields */ } and I want fetch all categories with joined topics and joined posts using JPQL query. I

Ignore a FetchType.EAGER in a relationship

寵の児 提交于 2020-01-19 04:48:31
问题 I have a problem with EAGERs relationships in a big application. Some entities in this application have EAGER associations with other entities. This become "poison" in some functionalities. Now my team needs to optimize this functionalities, but we cannot change the fetch type to LAZY , because we would need to refactor the whole application. So, my question: Is there a way to do a specific query ignoring the EAGERs associations in my returned entity? Example: when a I have this entity Person

Ignore a FetchType.EAGER in a relationship

旧街凉风 提交于 2020-01-19 04:47:27
问题 I have a problem with EAGERs relationships in a big application. Some entities in this application have EAGER associations with other entities. This become "poison" in some functionalities. Now my team needs to optimize this functionalities, but we cannot change the fetch type to LAZY , because we would need to refactor the whole application. So, my question: Is there a way to do a specific query ignoring the EAGERs associations in my returned entity? Example: when a I have this entity Person

jpa - transforming jpql join query to criteria api

回眸只為那壹抹淺笑 提交于 2020-01-17 08:38:08
问题 I was trying to transform this JPQL query; SELECT s FROM QuestionSet s JOIN s.questions q WHERE q.appointedRepetition.date < :tomorrow to its criteria api equivalent, here is what I have so far: DateTime tomorrow = DateTime.now().plusDays(1).withTime(0,0,0,0); CriteriaBuilder criteriaBuilder = JPA.em().getCriteriaBuilder(); CriteriaQuery<QuestionSet> query = criteriaBuilder.createQuery(QuestionSet.class); Root<QuestionSet> root = query.from(QuestionSet.class); Join<QuestionSet, Question>

Query inside a recursive function in JPQL

淺唱寂寞╮ 提交于 2020-01-16 06:27:49
问题 I am new to Jpa and jpql, I need to generate dropdown menu from a query. In codeigniter it was easy. I'd just do query inside a query in recursive function. Here is the sample function main_menu($base_id, $id=NULL, $class=NULL, $selected=NULL ) { $this->db->select('id, url, parent_id,title,'); $this->db->where('parent_id',$base_id); $this->db->order_by('sort_order','asc'); $query = $this->db->get('tbl_menu'); if($query->num_rows()>0) { if($this->level == 0) echo "<ul class='".$class."' id='".

How to get jpql query from sql query?

穿精又带淫゛_ 提交于 2020-01-16 05:00:09
问题 i can make sql simple query in JPQL like this and its work well : Query query = em.createQuery("SELECT p2 FROM Zp01 p2 where p2.gestionnaire IN (SELECT d.libelle FROM Affaire d)") ; liszp01general= (List<Zp01>) query.getResultList(); but i cant translate this query to JPQL thats already working in sql : SELECT p2.* from zp01 p2 join (SELECT TYPEC,count(TYPEC) as cnt_typec FROM planning_cuisson group by TYPEC HAVING COUNT(TYPEC) > 0) p1 where p2.type_cuisson=p1.typec order by cnt_typec asc ; i