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 ...
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)
...
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...
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?
...
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...
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...
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...
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...
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)
...
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...
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, ...
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?
...
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; ...
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...
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...
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 ...
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 ...
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.
...
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...
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 & ...