jpa

Hibernate collections within collections

I have a Hibernate entity named Menu which has a collection of Groups, each group in turn has a collection of MenuItems. So as an example, a menu can be for a restaurant, groups can be Lunch and Dinner and the menuItems within these can be Pasta, Burger, Salad. The problem I'm having is that once i have created the menu and saved it ...

persisting a new object without having to fetch the associations

I have the following mapping in an Ad entity: class Ad ... { @Id @Column(name = "id", unique = true, nullable = false) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_ad_generator") private Long id; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "category_id", nullable = false) ...

EclipseLink: Checking current transaction isolation level

I have a standalone Java application that uses EclipseLink 2.0.1. It is configured by a persistence.xml, and then does something like: final EntityManagerFactory emf = Persistence.createEntityManagerFactory("xy"); final EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); .... em.getTransaction().commit(); I want...

How to fill entity's field with separate queue in Hibernate?

Hi there! I have an entity, say @Entity public class Category { private String name; private int usersInCategory; } I want to fill usersInCategory field with some aggregating SQL query (select count(*) ... group by ...). How can I do this in Hibernate? ...

JPA and DTO's, best way to create DTO's?

We're to use DTO's to send data to and from the presentation layer. I have a method on a service object called PostAd which posts an advertisement entered by a user. The Ad has an association to another object called AdValues, which contain values for the Ad (title, price, description etc) @Entity public class Ad { @OneToMany Se...

Map a NativeQuery into an entity

Hello everyone, I'm having trouble trying to map a native SQL query using JPA, and Hibernate as a provider. This is the code for the entity that I'm using for this purpose: package com.prueba.entities; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EntityResult; import javax.persistence.Field...

Empty Join Table resulting from JPA ManyToMany

I have an application in which I am trying to implement ManyToMany relation between 2 entities using Hibernate as my JPA provider. The example I am trying is an uni-directional one, wherein a Camera can have multiple Lenses and Lense can fit into multiple Cameras. Following is my entity class...(Just pasting the relevant part of it) C...

Getting the ID of the persisted child object in a one-to-many relationship.

I have two entity classes A and B which looks as follows. public class A{ @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @OneToMany(mappedBy = "a", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) private List<B> blist = new ArrayList<B>(); //Other class members; } Class B: pu...

Using group by and having in a JPA query

How would you do the following using the JPA query language? select * from person where email in (select email from person group by email having count(email)>1) ...

JPA, MySQL, Hibernate & Maven Skeleton

Hello, I've been trying to get a simple skeleton app to run (and commit to the DB) using JPA, MySQL, Hibernate & Maven, however I'm having problems. Listed below are my 2 trivial classes, my pom.xml, and my META-INF/persistence.xml I can build the project without any problem (mvn clean install), however running it (mvn exec:java -Dexe...

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

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, ...

Are SQL injection attacks possible in JPA?

I'm building a Java Web Application using Java EE 6 and JSF-2.0, using the persistence API for all database operations. The back-end is MySQL, but I have used the EntityManager functions and Named Queries in EJB-QL for all operations. Are SQL injection attacks possible in this case? ...

JPA Mapping Issue - Modelling direction requested

Hello, I'm having a problem modelling the following problem in JPA. I have a JPA Entity class 'User', like so: (accessors/mutators/extraneous fields/extraneous JPA configuration omitted for brevity) @Entity class User { @Id @Generated Value long id; @OneToMany Report contributorReports; ...

Vaadin and JPA container, store beans or not

I'm a first-timer to this and would like to have some guidance regarding how to store objects in a database.. I have an object Person, with a couple of fields in it. I have one PersonContainer which loads all the objects from the database. What is best of these two: (or if they both suck, tell me what's the right thing to do) Store th...

Best Practises for Polymorphic JPA via Annotations

I'm trying to set up polymorphic behaviour using Hibernate with JPA annotations. It seems sensible (maybe even necessary) to create an (abstract) class encapsulating the state and behaviours required for the inheritance hierarchy to participate in persistence; for example I need to annotate an Id property, which I cannot do in an inte...

Simple and reliable in memory database for fast java integration tests with support for JPA

My integration tests would run much faster if I used in-memory-database instead of PostgreSQL. I use JPA (Hibernate) and I need an in-memory-database that would be easy to switch to using JPA, easy to setup, and reliable. It needs to support JPA and Hibernate (or vice verse if you will) rather extensively since I have no desire to adopt ...

JPA with Multiple Servers

I am currently working on a project that uses JPA (Toplink, currently) for its persistence. Currently, we are running a single application server, but, for redundancy, we would like to add a load balancer and another application sever (and possibly more as it grows). First, I'm running into the issue of JPA caching. Since two processes ...

How do i use JPA 2 to connect to multiple data sources?

I have two databases in MSSQL ,and i want to connect to them using JPA2 I have managed to get it working with one . Can some one help me how do i do that? Thanks a Lot. ...

How to run agregate function like Sum on two columsn in JPA and display there results?

Hi, I am new to JPA.So my question would sould so simple to some. :) Below is the Simple Query in SQL which i would like to convert to JPA.I already have the an Entity Class as TimeEnt SELECT SUM (TimeEntryActualHours) As UnBilledHrs,SUM (TimeEntryAmount) As UnbilledAmount From TimeEnt Where MatterID = 200; Thanks a lot for you hel...

EJB3 RMI client

Hello Everybody! I'm currently working with on a fat client application using a self written RMI server (10 years ago). The server sends EJB1.1/2.0 beans to the client who has full access to these remote objects. After commiting a transaction, all dirty beans are persisted by the server. The plan is to replace the server by a JBoss5 & ...