jpa

How to eagerly fetch a single "default" entity from a collection in EJB3/JPA

I have a Person entity with multiple phone numbers. @OneToMany(mappedBy="person", cascade=CascadeType.ALL) public Set<PhoneNumberOfPerson> getPhoneNumbers() { return phoneNumbers; } Now I would like to implement a "get default phone number" method for Person that is eagerly fetched. This default phone number is one of the phone ...

Calculated field vs Complex queries in a database (using JPA)

We have a stock control system which manages the flow of certain items in and out of the business or given location. We have records in the db representing the movement of stock and the inbound and outbound deliveries. If you were to add up all the inbound deliveries and then the outbound deliveries and subtract one from the other, you ...

Cascading Deletes/Updates using JPA or Inside of Database?

Performance is key: Is it better to cascade deletes/updates inside of the Database or let Hibernate/JPA take care of it? Will this effect the ability to query for the data if cascades are inside of the DBMS? I am using HSQLDB if that matters. ...

Nested JPQL queries in hibernate, are they creating nested objects?

Was thinking about a scenario, suppose two entities, Customer and Order. Suppose I want to see all distinct customers who fulfills a certain criteria, who has one or more orders fulfilling a criteria. If I use something like: Select distinct cust from Customer cust join cust.orders order where order.x = 'y' and cust.z = 1 The above ...

JPA Implementations - Which one is the best to use?

Hi all, I have made use of the following JPA implementations: Hibernate, Toplink, OpenJPA Each of them has their own strengths and weaknesses. I found Hibernate the most advanced of the three except that it mixed some of its own enhancements with JPA which made it difficult to switch out to other providers. Most importantly, its que...

How to solve lazy initialization exception using JPA and Hibernate as provider

I am working on a project for a customer who wants to use lazy initialization. They always get "lazy initialization exception" when mapping classes with the default lazy loading mode. @JoinTable(name = "join_profilo_funzionalita", joinColumns = {@JoinColumn(name = "profilo_id", referencedColumnName = "profilo_id")}, inverseJoinColumn...

How To Configure Query Cacheing in EclipseLink

I have a collection of states, that I want to cache for the life of the application, preferably after it is called for the first time. I'm using EclipseLink as my persistence provider. In my EJB3 entity I have the following code: @Cache @NamedQueries({ @NamedQuery( name = "State.findAll", query = "SELECT s FROM State...

Storing username that last modified database row via EJB3.0 and JPA

I'd like to store username that has last modified table row to as a field in every table. I have following setup: an user logs in, web layer calls some EJB 3.0 beans. Those EJB beans create and modify some JPA entities. Now, I'd like that username (from weblayer) would be automatically stored to every JPA entity (and database row) that...

EJB3 and manual hierarchy persistence.

I have a legacy database, which I am using EJB3 to model. The database is in quite a poor shape, and we have certain unusual restrictions on how we insert into the DB. Now I want to model the database in a hierarchy that fits in with the DB strucuture, but I want to be able to manually insert each entity individually without the persiste...

HQL for finding starting index of objects in a predefined order?

Using HQL, I would like to search for the starting index of sequenced objects. For example, if I have the following persisted classes: <class name="Word"> <id name="id" type="int"> <meta attribute="scope-set">protected</meta> <generator class="native"/> </id> <many-to-one name="sentence" class="Sentence"/> <property name="...

Does between in HQL compare strictly or not?

if I write in HQL A between 5 and 10 is that equivalent to A >= 5 and A <= 10 or A > 5 and A < 10 or some other of the 4 combinations? ...

Where can I find a list of all HQL keywords?

Where can I find a list of all HQL keywords? ...

JPA reserverd keywords to postgres

I'm using JPA with a postgres DBMS and I'm trying to create a new entity that maps to the table "User". This is a very common problem as User is a reserved word in Postgres. My question is, how can i "escape" the reserved keyword or set JPA to escape it? I tried @Table(name = "\"user\"") with no luck: 2009-02-25 15:43:14,218 ERROR...

JPA: please help understanding "join fetch"

I have the following entity structure: Business --> Campaign --> Promotion, where ONE Business can have MANY Campaigns and ONE Campaign can have MANY Promotions. Both one-to-many relations are declared as LAZY. One place in my code, I need to eagerly fetch both collections from a Business, so I do: Query query = entityManager.create...

How to remove trailing whitespace in a database column?

I have an EJB 3 Entity bean that has a String property annotated with: @Column(unique=true). This value is set from a JSF page. Everything works fine as long as the user does not add whitespace add the end of the input field. In that case "someName" and "someName____" are treated not unique and are stored in the database. Is there a con...

Is it possible to use hibernate as Glassfish's persistence provider?

Is it possible to use hibernate as Glassfish's persistence provider and if so HOW? ...

Hibernate Annotations - Which is better, field or property access?

This question is somewhat related to http://stackoverflow.com/questions/305880/hibernate-annotation-placement-question. But I want to know which is better? Access via properties or access via fields? What are the advantages and disadvantages of each? ...

ConcurrentModificationException and a HashMap

I am persisting objects using JPA. The Main object has an owning One-Many relationship with another object. The other object is stored in a HashMap. What sort of synchronization would fix this problem? It seems to happen at completely random times and is very unpredictable. Here is the exception I get: Exception in thread "pool-1-t...

Ejb-QL DISTINCT ON

Is it possible to use PostgreSQL-like DISTINCT ON in EJB-QL query? What i need to do is to fetch from db records that are distinct on 3 of 10 columns. ...

EJB3 case-sensitive annotations

We are connecting to a SQL Server to persist our EJB3 objects. These objects are annotated up with @Column. If the column name in the database starts with a capital letter (E.g. OrderName) will the ejb annotation have case sensitivity issues if the element is defined like such: @Column String orderName Thanks ...