eclipselink

Read Data from JPA the ways to do it

怎甘沉沦 提交于 2019-12-25 07:37:56
问题 I read in the documentation and i see that to read the jpa data i need to use the following code. this is the only way to read the data from the JPA tables via sql? factory = Persistence.createEntityManagerFactory("abc"); EntityManager entityManager = factory.createEntityManager(); Query query = entityManager.createQuery("SELECT p FROM " + className + " p"); 回答1: There are several ways to read data using JPA. The example you provided is using JPQL. Additionally, you can: execute a native SQL

JPA throws no EntityExistsException but generates a duplicate row (auto generated PK)

喜欢而已 提交于 2019-12-25 07:29:13
问题 I am new to JPA and was experimenting a bit in hope of figuring out the Entity lifecycle model. I expected the code below to throw an EntityExistsException. However, instead of throwing the expected exception, it just creates a new row in database table with a new primary key (incremented by one). Can anyone explain this? I suspect it might have something to do with the @GeneratedValue annotation on my ID field in combination with my autoincrementing primary key in the corresponding table.

insert new entity that has an unidirectional many-to-many relationship generate cascade-persist instead of cascade-merge

老子叫甜甜 提交于 2019-12-25 07:24:06
问题 I have two entities Role and Grant with the following mapping: public class Role extends BaseBean { private static final long serialVersionUID = 1L; private String name; private Set<Grant> grants = new HashSet<Grant>(); // get set } public class Grant implements Serializable { private static final long serialVersionUID = 1L; private String id; private String data; } mapping orm: <entity name="q2role" class="tn.waycon.alquasar2.adm.model.Role"> <attributes> <basic name="name"> <column length=

EclipseLink not populating Lazy OneToOne with nested Lazy OneToMany Relation

耗尽温柔 提交于 2019-12-25 06:25:36
问题 I migrated from Hibernate to EclipseLink because we needed composite primary keys which EclipseLink handles well and Hibernate doesn`t (really does not!). Now I am fixing our JUnit tests, I get issues with tons of OneToMany relations not loaded. I have the following classes: DatabaseSession.java package platform.data; import java.util.List; import java.util.Objects; import java.util.Set; import java.util.function.BiConsumer; import java.util.stream.Collectors; import javax.persistence

How to do group by substring in Eclipselink?

醉酒当歌 提交于 2019-12-25 05:51:17
问题 I'm trying to group the store by store country and see how many stores there are in each country. The store country happens to be the first 2 characters of the store's code. That means if the store code is "US000010", the country is "US" My entity object: ... public class Store { @column(name = "code") private String code; ... } My JPQL is: SELECT substring(s.code, 0, 2), count(s) FROM Store s GROUP BY substring(s.code, 0, 2) This keeps throwing me ORA-00979: not a GROUP BY expression , which

UserTransaction failed when call utx.begin() throws “java.lang.IllegalStateException: Operation not allowed”

天大地大妈咪最大 提交于 2019-12-25 05:04:16
问题 i want to use ejb and jpa controller, in netbeans the controller is generated automatically... I try to call the jpa controller from class (UniversidadServiceEJB) that is a session bean stateless, I debugged the project and the UserTransaction and EntityManagerFactory is created successfully but when call the method utx.begin in the jpa controller (UniversityJpaController) throws this exception: java.lang.IllegalStateException: Operation not allowed. at com.sun.enterprise.transaction

Understanding of TABLE_PER_CLASS with keys in eclipselink

前提是你 提交于 2019-12-25 04:23:04
问题 I have a simple Java EE 7 Web App with Eclipselink and the TABLE_PER_CLASS inheritance strategy. Following classes: @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Entity public abstract class AbstractService implements Serializable { private static final long serialVersionUID = 7041207658121699813L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @ManyToOne @JoinColumn private PersonGroup personGroup; } @Entity public class Service extends AbstractService

Installing JPA pluggin for Eclipse juno

笑着哭i 提交于 2019-12-25 04:13:47
问题 I'm new to eclipse, I want to install JPA plugging so I can benefit of the JPA wizard and import entity classes easily ... I tried to download it using eclipse install software menu using eclipse juno repository, I found many links, I tried to download them all, but during the downloading, I get an error saying 'installing software' has encountered a problem, An error occurred while collecting items to be installed : An error occurred while collecting items to be installed session context was

JPA How to get the number of parameter markers used in Criteria API?

隐身守侯 提交于 2019-12-25 03:55:05
问题 How do I get the number of parameter markers used in Criteria API? I am using Criteria API to create SQL statement with IN keyword that have many parameter markers. CriteriaBuilder cb = ... ... CriteriaBuilder.In<String> in = cb.in(...); ... for (...) { in.value(...); } I started getting SQLException "Prepared or callable statement has more than 2000 parameter markers." Is there a way to get the actual number of parameter markers used so far? I could count them by myself, but it is error

Java NullPointerException at jpa.EntityManagerImpl.getActivePersistenceContext

南笙酒味 提交于 2019-12-25 03:27:30
问题 I am developing an application using Eclipse IDE, Eclipse-Link, JPA, and MySQL. During a find operation in the main application I get the following exception from the Data Access layer: Exception in thread "Thread-1" java.lang.NullPointerException at org.eclipse.persistence.internal.jpa.EntityManagerImpl.getActivePersistenceContext(EntityManagerImpl.java:1931) at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.begin(EntityTransactionImpl.java:93) at database.dao.DAO