openjpa

Can JPA return results as a map?

徘徊边缘 提交于 2019-11-30 04:26:16
We are currently build a map manually based on the two fields a named query returns, because JPA only provides a getResultList(). @NamedQuery{name="myQuery",query="select c.name, c.number from Client c"} HashMap<Long,String> myMap = new HashMap<Long,String>(); for(Client c: em.createNamedQuery("myQuery").getResultList() ){ myMap.put(c.getNumber, c.getName); } But I feel like a custom mapper or similar would be more performant since this list could easily be 30,000+ results. Any ideas to build a Map without iterating manually. (I am using OpenJPA, not hibernate) wrschneider There is no standard

DDL generation and general persistence.xml settings (OpenJPA)

你离开我真会死。 提交于 2019-11-30 04:24:52
问题 Summary I'm trying to run a Java web application JPA 2.0 example. The example application was written to run in Glassfish , using EclipseLink as JPA provider. I would like to convert it to run in TomEE with OpenJPA as the JPA provider, but I can't any detailed tutorials for getting up and running with OpenJPA . Problem I'm having trouble converting persistence.xml to work with OpenJPA instead of EclipseLink . More specifically, the given persistence.xml doesn't specify: Entity classes. Are

updating multiple rows using JPA

本小妞迷上赌 提交于 2019-11-30 03:56:15
I want to update all fields of a table that has value of colum NAME as 'PCNAME'. The table name which i want to update is XYZ.I want to update only some fields and not keep some unchanged. This will affect many rows and not a single row as there will be many rows with NAME='PCNAME' How can i do it using JPA.I have entity class associated with this table. You can either do it the object oriented way or using an update query. Object oriented: public void setNameOfAllEntities(String newname){ List<MyEntity> items = entityManager.createQuery("from MyEntity", MyEntity.class) .getResultList(); for

What's the lazy strategy and how does it work?

折月煮酒 提交于 2019-11-29 12:17:33
I have a problem. I'm learning JPA. I'm using embedded OpenEJB container in unit tests, but only working is @OneToMany(fetch=EAGER) . Otherwise is the collection allways null. I haven't found, how the lazy strategy works, how the container fills the data and in which circumstances triggers the container the loading action? I have read, that the action triggers when the getter is being called. But when I have the code: @OneToMany(fetch = LAZY, mappedBy="someField") private Set<AnotherEntities> entities = new Set<AnotherEntities>(); ... public Set<AnotherEntities> getEntities() { return entities

select from two tables using JPQL

扶醉桌前 提交于 2019-11-29 11:15:39
I'm using JPQL to retrieve data. I can get data using the statement List persons = null; persons = em.createQuery("select p.albumName from PhotoAlbum p , Roleuser r where r = p.userId and r.userID = 1"); Now I can get the album names using this: int i=0; for (i=0;i<persons.size(); i++) { System.out.println("Testing n "+ i +" " + persons.get(0)); } Now I want to get the album name and the roleuser's row named firstname I'm using the query persons = em.createQuery("select r.firstName , p.albumName from PhotoAlbum p , Roleuser r where r = p.userId and r.userID = 1").getResultList(); Now how do I

updating multiple rows using JPA

时光毁灭记忆、已成空白 提交于 2019-11-29 01:33:16
问题 I want to update all fields of a table that has value of colum NAME as 'PCNAME'. The table name which i want to update is XYZ.I want to update only some fields and not keep some unchanged. This will affect many rows and not a single row as there will be many rows with NAME='PCNAME' How can i do it using JPA.I have entity class associated with this table. 回答1: You can either do it the object oriented way or using an update query. Object oriented: public void setNameOfAllEntities(String newname

Can JPA return results as a map?

半城伤御伤魂 提交于 2019-11-29 00:30:01
问题 We are currently build a map manually based on the two fields a named query returns, because JPA only provides a getResultList(). @NamedQuery{name="myQuery",query="select c.name, c.number from Client c"} HashMap<Long,String> myMap = new HashMap<Long,String>(); for(Client c: em.createNamedQuery("myQuery").getResultList() ){ myMap.put(c.getNumber, c.getName); } But I feel like a custom mapper or similar would be more performant since this list could easily be 30,000+ results. Any ideas to build

websphere 7 and (application based) open-jpa 2

落花浮王杯 提交于 2019-11-28 12:27:25
I want to not use the built in Websphere 7 jpa plugin, instead use an application WEB-INF/lib/open-jpa 2 and a proprietary persistence provider. I cannot install the OSGI and JPA 2 feature pack for Websphere. Originally, I was getting a sax parse error simply trying to load the persistence.xml (version="2" not supported). The error was thrown by a class in open-jpa 1.2.3. When I run websphere/appserver/bin/wsjpaversion.bat, the open-jpa 1.2.3 jar is displayed. By default it overrides the open-jpa 2 jar in the app. I created a shared library containing the open-jpa 2 jar with this config option

select from two tables using JPQL

夙愿已清 提交于 2019-11-28 04:19:47
问题 I'm using JPQL to retrieve data. I can get data using the statement List persons = null; persons = em.createQuery("select p.albumName from PhotoAlbum p , Roleuser r where r = p.userId and r.userID = 1"); Now I can get the album names using this: int i=0; for (i=0;i<persons.size(); i++) { System.out.println("Testing n "+ i +" " + persons.get(0)); } Now I want to get the album name and the roleuser's row named firstname I'm using the query persons = em.createQuery("select r.firstName , p

JPA Implementations - Which one is the best to use? [closed]

微笑、不失礼 提交于 2019-11-27 20:02:46
I have made use of the following JPA implementations: Hibernate, Toplink, OpenJPA Each of them has their own strengths and weaknesses. I found Hibernate the most advanced of the three except that it mixed some of its own enhancements with JPA which made it difficult to switch out to other providers. Most importantly, its query parser was much more lenient when interpreting JPA. They make it slightly difficult to get the correct libraries to support hibernate because I found it a mission trying to get the right versions of all the dependencies. Toplink was ok but one is left with the feeling