jpa

Process files in Java EE

I have a system that is supposed to take large files containing documents and process these to split up the individual documents and create document objects to be persisted with JPA (or at least it is assumed in this question). The files are in the range of 1 document to 100 000 in each file. The files come in various types Compressed...

JPA remove constraints at run time

I'm deleting entities from a table with a one to many relationship to the same entity (representing node hierarchy). If I make the xincoCoreNodeId relationship a cascade all it works but I don't want that in the real application. I don't want removing a leaf removing its parent. Is there a way to modify this relationship at run time or d...

How can I remove an item from a Hashmap in Hibernate ?

Hello, I try to delete an item from a hash map with hibernate. Here is my config on the collection: @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) @OneToMany(mappedBy = "game", cascade = CascadeType.ALL, fetch = FetchType.LAZY) @Where(clause = "charactType='charact'") @MapKey(name = "shortcut") @Cascade(org.hibernate.annotations....

Multiple database with Spring+Hibernate+JPA

Hi everybody! I'm trying to configure Spring+Hibernate+JPA for work with two databases (MySQL and MSSQL) my datasource-context.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/a...

unique constraint check based on a parameter in the parent table

Table User has (userId, scoreType, ...) @Table(name = "User", uniqueConstraints = @UniqueConstraint(columnNames = userId)) -- scoreType could be either points or percentage Table UserScore (id, userId, points, percentage) I would like to provide the flexibility to store either points or percentage based on user.scoreType. So if ...

xapool connection timed out

I'm using xapool (org.enhydra.jdbc.pool.StandardXAPoolDataSource) with Spring and JPA and I'm getting connection timed out errors. I found the "checkLevelObject" setting, but it doesn't seem to have helped. Should that have fixed it? Are there other setting that I could use to test the connections and have them replaced without impacting...

Hibernate and padding on CHAR primary key column in Oracle

I'm having a little trouble using Hibernate with a char(6) column in Oracle. Here's the structure of the table: CREATE TABLE ACCEPTANCE ( USER_ID char(6) PRIMARY KEY NOT NULL, ACCEPT_DATE date ); For records whose user id has less than 6 characters, I can select them without padding the user id when running queries using SQuirre...

Using Hibernate/JPA without relationships and avoiding multiple DB calls

It seems to me that when you use relationships in Hibernate/JPA that using relationships like OneToMany can have a performance boost on reads because only one database call would need to be run to get a parent entity and all children entities. I want to avoid using relationships and just map foreign key columns as normal columns due to ...

How to make a property nullable in JPA - GAE/J?

I have a entity class User. I want to add some more properties but to keep them nullable. I want to know the annotation used for this in JPA. I am using JPA in Google App Engine. Thanks ...

What is a natural identifier?

When reading through the Hibernate documentation I keep seeing references to the concept of a "natural identifier". Does this just mean the id an entity has due to the nature of the data it holds? IE: A user's name+password+age+something are its identity? ...

Database Diff Tool

As a Java Developper using JPA/Hibernate, I am looking for a will help diff a database that has been generated by Hibernate with a production database. I've already looked at LiquiBase's abilities LiquiBase which is quite nice... Unfortunlately it is plagued by some weird bugs: Re-Create Foreign Keys for no reason Re-Create Indexes fo...

In spring, what code is used to inject the value for the @PersistenceContext annotated variables?

Using a ClassPathXmlApplicationContext object I want to get the same EntityManager that is being used by other parts of the app which get it injected via: @PersistenceContext(unitName="accessControlDb") private EntityManager em; Using ctx.getBean("access-emf") I can get the EntityManagerFactory which is defined in the applicationConte...

Ordering by a Column that's not in the Group By or Enapsulated in an Aggregate

I have a problem getting this JPA query to work on MS SQL Server 2008. The background is as follows: Users create jobs for clients, of which there are many. I am displaying a list of his most recently used clients to the user to make the selection easier. SELECT DISTINCT c FROM Client c JOIN c.jobs j WHERE j.user = ?1 O...

JPA Composite key (all fields are notNull and PRI)

Hi all, I saw that exist more then one way to map a Composite Key with JPA. But in my case is kind of different: I have a table with only 2 column: mysql> desc mytable; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------...

Backup a database using JPA

I'm working on a database backup engine using JPA. Everything is working fine but I'm having issues figuring this issue. I know is related to how I defined the Entities. First here's a brief on how the system works: Create a Derby database instance in a selected directory Connect to the source database and scrol thru the tables fetchi...

Get fresh data for a list of entities

We're using jpa with Toplink as an implementation and came up with a problem about refreshing lists of entities. Basically this is the scenario: private List<Entity> findAll() { final String sql = "SELECT e from " + anEntityClass.getSimpleName() + " e"; final Query query = itsManager.createQuery(sql); List<Entity> result = ...

JPA Spring Hibernate Dao List problem

I am using JPA/Spring/Hibernate as my persistence mechanism for my application. Currently I am running into unit test problems where when I ask for some objects I get the right amount returned from the DAO that correspond to the number of rows in the database, but they are all of the exact same instance. Here is the findByName() metho...

What is the correct way of overriding hashCode () and equals () methods of persistent entity?

I have a simple class Role: @Entity @Table (name = "ROLE") public class Role implements Serializable { @Id @GeneratedValue private Integer id; @Column private String roleName; public Role () { } public Role (String roleName) { this.roleName = roleName; } public void setId (Integer id) { ...

To equals and hashcode or not on entity classes, that is the question.

I have been trying to reason about the best way to handle whether it is generally good practice to implement hashcode and equals on entities (I mean entity in the general sense but in most cases it will be a JPA entity). In Chapter 24 of the Hibernate manual http://docs.jboss.org/hibernate/core/3.3/reference/en/html/best-practices.html ...

JPA Merge Is Causing Duplicates

I have the entity classes below. When a user first signs up, only the username and password are supplied, so the list of accounts (think profiles) is empty. Later, when they add an account, the user object is updated in the client, passed to the server, and then entityManager.merge(user) is called. When the user is merged, the account...