jpa-2.0

Is Select EXISTS() possible in JPQL?

别等时光非礼了梦想. 提交于 2019-11-30 17:14:41
I'm trying to run a query that checks if some conditions are true and returns a simple boolean result as output. What makes it slightly tricky is that one of the conditions is to test for whether no results are returned for a set of criteria. I'm currently using JPA-2.0 with hibernate as my provider, backed by MySQL. I have gotten an example query working fine in MySQL, but when trying to get it running in JPQL it flops. The MySQL query looks a bit like this: Select exists(Select statement with criteria) or not exists(Select statement with criteria); I also got the same output using CASE, but

QueryDSL and Play Framework

旧时模样 提交于 2019-11-30 16:04:13
I'm using QueryDSL with JPA2 for some time, and it's the most powerful combination for ORM I know. JPA Criteria API is a disaster. With QueryDSL I've forgotten about JPQL too. I'd like to use QueryDSL with Play! Everything looks very good in Play except those inline parts of JPQL as strings. It reminds me of CakePHP... I'd like to have refactoring-proof querying language in Play (and some other things :) ). QueryDSL usage would be straightforward. It needs EntityManager only. But QueryDSL has this APT class generator (just like the one from Hibernate for citeria API). Does anyone managed to

JPA ManyToMany Join Table has all attributes as PK

此生再无相见时 提交于 2019-11-30 15:57:08
I'm using Hibernate 3.3.1 and am following along in modelling this sample table structure , but I'm having trouble creating a join table with extra attributes. It's the many-to-many relationship between the Order and Product table. The join table is the Order Detail table. I followed the approach mentioned here . Now I have the entities @Entity @Table(name = "Orders") public class Order { @OneToMany(mappedBy="order") private List<OrderDetail> orderItems; } and @Entity @Table(name="PRODUCTS") public class Product { @OneToMany(mappedBy="product") private List<OrderDetail> orderItems; } and

HIBERNATE - JPA2 - H2 - Querying @ElementCollections HashMap by key

家住魔仙堡 提交于 2019-11-30 15:51:06
I'm using hibernate-entitymanager 3.6.4.Final and h2 database 1.3.155 I'm using the H2Dialect. I'm having trouble filtering records by elements in an @ElementCollection. Here is my entity @Entity public class Item { @Id @GeneratedValue(strategy = GenerationType.AUTO) @MapKeyColumn(name="name", length=50) @Column(name="value", length=100) protected Map<String, String> attributes; /* etc. */ } Here is my query : Item item = em.createQuery("FROM Item i JOIN i.attributes a WHERE KEY(a)='myAttrName'").getSingleResult(); Here is the error message : 4971 [main] WARN org.hibernate.util

Weblogic 10.3.3 trying to load org.eclipse.persistence.jpa.PersistenceProvider instead of configured Hibernate Provider

和自甴很熟 提交于 2019-11-30 15:45:09
Good Day all , I am having this problem since many days now , I was able to successfully deploy JPA2.0 appliaction on weblogic 10.3.3 , the application can run select queries using JPA. But when I try to run a create or update information on the same table I get below exception [code] java.lang.ClassCastException: org.eclipse.persistence.jpa.PersistenceProvider cannot be cast to javax.persistence.spi.PersistenceProvider [/code] This is very strange because in my persistence.xml I have provided hibernate as JPA provider , the persistence unit defined is like below [code] <persistence-unit name=

Any drawbacks of using Hibernate EntityManager (vs. Hibernate Core)?

假如想象 提交于 2019-11-30 13:53:29
问题 The Hibernate EntityManager documentation states, that: You may use a combination of all three together, annotations without JPA programming interfaces and lifecycle, or even pure native Hibernate Core, depending on the business and technical needs of your project. You can at all times fall back to Hibernate native APIs, or if required, even to native JDBC and SQL. Code that uses the JPA API (EntityManager) is clearly more portable (even with occasional fallbacks to Hibernate Core). But would

Using JPA2 in Tomcat 6: @PersitenceContext doesn't work, EntityManager is null

余生颓废 提交于 2019-11-30 13:52:12
I am using JSF2 with Pure JPA2. But the problem is with entityManager, @PersistenceContext private EntityManager entityManager; Here entityManager is not getting injected and always null. Can some one please help me what is wrong in my code. Here is my configuration. User.java @Entity @Table(name="USER") public class User { private int id; private String name; private String surname; @Id @SequenceGenerator(name="user_id_seq_gen", sequenceName="USER_ID_GEN_SEQ", allocationSize=1) @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="user_id_seq_gen") @Column(name="ID", unique = true,

JPA: question on impedance mismatch in OneToMany relations

与世无争的帅哥 提交于 2019-11-30 13:30:27
问题 I have a question about JPA-2.0 (provider is Hibernate) relationships and their corresponding management in Java. Let's assume i have a Department and an Employee entity: @Entity public class Department { ... @OneToMany(mappedBy = "department") private Set<Employee> employees = new HashSet<Employee>(); ... } @Entity public class Employee { ... @ManyToOne(targetEntity = Department.class) @JoinColumn private Department department; ... } Now i know i have to manage the Java relationships myself,

Criteria API: Fetch of a list returns repeated main entity

三世轮回 提交于 2019-11-30 13:21:27
问题 I have the following Entities; Ticket contains a set of 0,N WorkOrder: @Entity public class Ticket { ... @OneToMany(mappedBy="ticket", cascade = CascadeType.ALL, fetch = FetchType.LAZY) private List<WorkOrder> workOrders = null; ... } @Entity public class WorkOrder { ... @ManyToOne @JoinColumn(nullable = false) private Ticket ticket; } I am loading Tickets and fetching the attributes. All of the 0,1 attributes present no problem. For workOrders, I used this answer to get the following code.

OneToMany - what are the differences between join table and foreign key?

风格不统一 提交于 2019-11-30 13:06:23
There is the possibility to disable the @OneToMany relationship join table with the @JoinColumn annotation. The default is a join table. What are the advantages and disadvantages for a production system for example? When should I use a join table and when not? Thank you. By default @OneToMany will create a join table only if you'll use unidirectional relationship . In other words, if you have Employee and Project entities and the Employee entity is defined as follows (assume there is no orm.xml entries for these entities) : @Entity public class Employee { // ... @OneToMany Set<Project>