jpa-2.0

Using Projections in JPA 2

断了今生、忘了曾经 提交于 2019-11-30 12:43:32
问题 I need to convert a Hibernate criteria query like the following curList = session.createCriteria(Islem.class) .createAlias("workingDay", "d") .setProjection(Projections.sum("amount")) .add(Restrictions.eq("currency", CURRENCY)) .add(Restrictions.eq("product", product)) .add(Restrictions.ne("status", INACTIVE)) .add(Restrictions.eq("d.status", ACTIVE)) .getResultList(); However in JPA (2) I have no idea how to implement the projection - in this case - the sum. It's odd that Hibernate and JPA

@PersistenceContext EntityManager thread-safety in Spring and Java EE

陌路散爱 提交于 2019-11-30 12:32:16
EntityManager is not thread-safe by definition. Servlets specs says that in non-distributed environment and without implementing SingleThreadModel , there is only one servlet instance per definition . Therefore, in Java EE when you inject an EntityManager through the @PersistenceContext into Servlet's field - it's not thread safe: public class MyServlet extends HttpServlet { // Not thread-safe, should be using EMF instead. @PersistenceContext private EntityManager em; } Is this correct to say that even though the default scope of Spring beans is singleton, the EntityManager is thread-safe as

What are the differences between Hibernate and JPA?

不想你离开。 提交于 2019-11-30 12:12:40
When i was in college learning about web programming, they told us about hibernate. We used it for a while, i even had the chance to work with it in a real scenario in a company for almost 8 months. Now that i completely switching to Java EE 6 ( Im in love :) ), I use JPA for my ORM needs. It is being a few months since i use it, but i dont really understand what are the differences between one and other. Why some people say one or other is better or worse? The way i do my mappings and annotations in both is almost the same... Maybe you can solve some of my doubts: -What are the advantages and

Orphans remain in database even with orphanRemoval=true on one-to-many relationship (JPA/Hibernate)

隐身守侯 提交于 2019-11-30 11:59:53
@Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @Table(name = "company_policies") @DiscriminatorColumn(name = "rule_name") public abstract class AbstractPolicyRule implements Serializable { @Transient private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; private String value; ... } _ @Entity public class Category implements Serializable { @Transient private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; @Column(name = "category_name") private String name; @OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL

Multiple @MappedSuperclass

喜你入骨 提交于 2019-11-30 11:27:20
I'm using JPA 2.0 and EclipseLink 2.2.0. I have a @MappedSuperclass, AbstractEntity, that is the basis for all my entities providing PK and auditing columns. I want to have another @MappedSuperclass extend that class and be the root for a TABLE_PER_CLASS inheritance strategy. At present, when building with Maven I receive header errors. Are multiple @MappedSuperclass allowed in an inheritance hierarchy? Mikko Maunu Multiple mapped superclasses are allowed in same inheritance hierarchy. It is not directly said so in specifications, but JPA 2.0 specification does not explicitly prohibit multiple

Criteria API: Fetch of a list returns repeated main entity

孤者浪人 提交于 2019-11-30 09:31:37
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. CriteriaBuilder criteriaBuilder = this.entityManager.getCriteriaBuilder(); CriteriaQuery<Ticket>

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

匆匆过客 提交于 2019-11-30 08:43:56
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 I have any advantages when using purely Hibernate Core? I wonder, if the JPA 2 model really fits on

How to map postgresql “timestamp with time zone” in a JPA 2 entity

这一生的挚爱 提交于 2019-11-30 08:09:35
I have a JPA 2 application ( with Hibernate 3.6 as the JPA implementation ) that uses Postgresql ( with the 9.0-801.jdbc3 JDBC driver ). I am having trouble mapping "timestamp with time zone" fields into my JPA entities. Here is an example: CREATE TABLE theme ( id serial NOT NULL, # Fields that are not material to the question have been edited out run_from timestamp with time zone NOT NULL, run_to timestamp with time zone NOT NULL, CONSTRAINT theme_pkey PRIMARY KEY (id ), CONSTRAINT theme_name_key UNIQUE (name ) ) I have tried to map as follows: @Entity @Table(schema = "content", name = "theme

Hibernate Parameter value [568903] did not match expected type [java.lang.Long]

喜夏-厌秋 提交于 2019-11-30 07:27:28
问题 I am using Hibernate 4 and I have a filter in JSF page to get search results. During execution of search I am getting the following exception java.lang.IllegalArgumentException: Parameter value [568903] did not match expected type [java.lang.Long] at org.hibernate.ejb.AbstractQueryImpl.validateParameterBinding(AbstractQueryImpl.java:370) at org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:343) at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:370)

Row numbering with p:dataTable

心已入冬 提交于 2019-11-30 07:14:41
问题 I have this query: SELECT @rownum:=@rownum+1 'no', m.title, m.author, REPLACE(SUBSTRING_INDEX(m.content, ' ', 20), '<br>', ' '), m.viewed, m.hashid FROM book m, (SELECT @rownum:=0) r WHERE m.lang = ?1 AND m.title like CONCAT('%',?2,'%') ORDER BY m.title asc The @rownum:=@rownum+1 part of the MySQL query for result numbering as Primefaces currently does not have a facility to display a numbering column. Is there a way to show Primefaces column numbering without having to do @rownum:=@rownum+1