jpa-2.0

How to set collection items for in-clause in jpql?

北慕城南 提交于 2019-12-07 02:02:25
问题 Is there a possiblity in JPA 2.0 to set a collection for in-clause in jpql-query? (I'm using EclipseLink) The next example fails: TypedQuery<Person> q = em.createQuery("select p from Person p where p.name in (?1)", Person.class); List<String> names = Arrays.asList(new String[] { "Bill Gates", "Steve Jobs" }); // THIS FAILS q.setParameter(1, names); List<Person> persons = q.getResultList(); for (Person p: persons) { System.out.println(p.getName()); } Is there another way to do it? 回答1: Here is

What's the default TemporalType for a temporal map key without a @MapKeyColumn or @MapKeyTemporal annotation?

和自甴很熟 提交于 2019-12-07 01:10:42
问题 I'm working on creating a JPA 2.0 Annotation compliancy kit for my internship. Right now, I'm wondering when a @MapKeyTemporal annotation is required and when it's optional... I know that when you define the column of the map key using @MapKeyColumn, the type the key should be mapped to can be derived by looking at the type of the column (and otherwise the type in the columndefinition). Thus, in this case, no @MapKeyTemporal annotation is necessary. When you attach the @MapKeyTemporal

JPA cascade persist - many to one

放肆的年华 提交于 2019-12-06 21:30:03
问题 I have a many to one relationship and I am trying to persist a child entity. public class Office { public int id; public int grades; @OneToMany public set<Employee> employees; } public class Employee{ @GeneratedValue(strategy=GeneratedValue.identity) public int empid; @ManyToOne(cascade=cascadeType.ALL) public Office office; } Office Id is already present in the database. But employee is not. Now if i am adding an employee and his grades must go into the office database. When i do the

selecting all rows from a database using JPA in WebSphere

不问归期 提交于 2019-12-06 19:02:51
问题 I am trying to implement a web service that uses open JPA to access the data layer. I am using websphere v7.0 and JPA 2.0. This service is going to get all rows out of a small db (about 6 rows and it won't expand much at all in the future). I am attempting to get all rows and return them through the user. I am right now creating the Session Bean that will retrieve the data. I have several JPA objects one of them (representing a row of all the data I want to return) looks like so... @Entity

jpa FlushModeType COMMIT

你离开我真会死。 提交于 2019-12-06 15:24:42
问题 In FlushModeType.AUTO mode, the persistence context is synchronized with the database at the following times: before each SELECT operation at the end of a transaction after a flush or close operation on the persistence context In FlushModeType.COMMIT mode, means that it does not have to flush the persistence context before executing a query because you have indicated that there is no changed data in memory that would affect the results of the database query. I have made an example in jboss as

JPA 2.0 EclipseLink Check for unique

喜你入骨 提交于 2019-12-06 15:01:13
问题 I have a collumn as unique=true.. in Exam class.... I found that because transactions are commited automaticaly so to force the commit i use em.commit() However i would like to know how to check if it is unique.Running a query isnt a solution because it may be an instert after checking because of the concurency.... Which is the best way to check for uniqness? List<Exam_Normal> exam_normals = exam.getExam_Normal(); exam.setExam_Normal(null); try { em.persist(exam); em.flush(); Long i = 0L; if

JPQL Not a Selected Expression error

末鹿安然 提交于 2019-12-06 14:57:14
I have the following JPQL in ProductList Entity class which executes as expected. select DISTINCT new foo.bar.ProductListDTO(p.prodId, " + CASE WHEN (p.prodId = 'ZCX') THEN CONCAT(p.prodDesc, ' - ', e.userId) ELSE p.prodDesc END) from ProductList p LEFT JOIN p.productCatalogueList c where c.userId='ZAM' ProductListDTO class public ProductListDTO(String prodId, String prodDesc, String userId) { this.prodId = prodId; this.prodName = prodDesc; this.userId = userId; } What I would like to achieve is add ORDER BY to the query. When p.prodDesc is added to ORDER BY clause, I am getting error not a

Execute some arbitrary sql in the current transaction in JPA 2.0

隐身守侯 提交于 2019-12-06 14:06:19
I am new to JPA 2.0/EclipseLink/Glassfish/JEE6, and have kind of a basic question. I have a DAO in which most of the entities are mapped directly to columns using JPA annotations, so I use the EntityManager, and it works great with no issues. However there are some tables in which I am constructing the SQL statements myself b/c they use oracle-specific functions (spatial), and I want very fine-grained control of the SQL. So I am building it with string concatenation. I would like to be able to enroll my SQL executions in the current transaction, if there is one already underway. So naturally I

Hibernate @OnDelete cascade same table

折月煮酒 提交于 2019-12-06 13:44:29
I am trying to create a table which captures parent child relationships, like a tree. I would like to maintain only two columns to capture this structure "id" and "parent". I want the database to be able to cascade delete all children when a row is deleted. Below is the Hibernate Entity that I have created, I have added the annotation @OnDelete(action = OnDeleteAction.CASCADE) however, the ON DELETE CASCADE is not added to the table when the table is created by Hibernate. Is this a bug? Or is there something I am missing or not understanding? @Entity public class Tree { @Id @Column(name = "id"

Retrieve primary key column definition of a generic entity in JPA

与世无争的帅哥 提交于 2019-12-06 12:38:44
Let say I have a generic method using JPA to list out entities public <T> List<T> list(Class<T> entity) throws Exception { List<T> result = new ArrayList<T>(); CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<T> query = builder.createQuery( entity ); Root<T> root = query.from( entity ); query.select( root ); //possible? query.orderBy(builder.asc(...)); result = em.createQuery( query ).getResultList(); return result; } Is there anyway for us to add orderby to the query and make it order by the primary key without specify the primary column as the expression? I mean, is there a