jpa

Is there a way to prevent null values from being persisted while allowing others through?

I have an existing JPA (EclipseLink) project where the desired behaviour is that if given a null value in a field for an entity, that null value should not be persisted. The use case is that we may get several partial updates to these entities from external sources. Those sources may give us a null value, that does not mean "nullify thi...

Hibernate: Check if object exists/changed

Assuming I have an object Person with long id String firstName String lastName String address Then I'm generating a Person-object somewhere in my application. Now I'd like to check if the person exists in the database (= firstname/lastname-combination is in the database). If not => insert it. If yes, check, if the address is the same....

Is it a missing implementation with JPA implementation of hibernate??

Hi all, On my way in understanding the transaction-type attribute of persistence.xml, i came across an issue / discrepency between hibernate-core and JPA-hibernate which looks weird. I am not pretty sure whether it is a missing implementation with JPA of hibernate. Let me post the comparison between the outcome of JPA implementation ...

Is it possible to override persistence.xml properties via configuration ?

JBOSS 5.1 / EJB 3 / JPA / MySQL For development we specify "hibernate.hbm2ddl.auto" as "update". This is done in several persistence.xml files embedded in several jars in an ear. For production we'd like to override this to specify "validate". Can this be done via configuration external to the ear? (I know it's possible to do this in...

@OneToMany without inverse relationship and without a join table?

This is a similar problem to "Hibernate @OneToMany without a separate join table", in that I need a @OneToMany relationship without a join table. However, I would also like to not define the inverse relationship. Removing the inverse seems to result in a join table being automatically generated... is there a workaround for this? ...

I found JPA, or alike, don't encourage DAO pattern

I found JPA, or alike, don't encourage DAO pattern. I don't know, but I feel like that, especially with server managed JTA managers. After adequate hands-on using DAO pattern, I started designing JPA based application around that pattern. But it doesn't fit in, IMO. I tend to lose quite a features of JPA and all. Well, suppose you fire...

spring 3.0 force singleton bean

<bean id="data.emf" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean" > <property name="persistenceUnitName" value="transactions-optional" /> </bean> from what i know by default all bean are singleton (according to document) but i somehow still getting duplicated creating of entitymanagerfactory. is there any p...

Spring 3.0 ORM with JPA 2.0 ClassCastException

I'm trying to use JPA 2.0 in Spring 3.0 ORM. The JPA vendor is Hibernate 3.5.0-Beta-3. It works well with JPQL, but when I tried to use CriteriaQuery, an exception happens: java.lang.ClassCastException: $Proxy50 cannot be cast to javax.persistence.TypedQuery at $Proxy38.createQuery(Unknown Source) at com.absorbx.re...

Verify JPA column mappings at load time

Current project recently had a mess of changes to the DB schema. These were largely style cleanups, such as ensuring that all columns followed a consistent naming pattern and were all_in_snake_case . I believe we got all of the column references in our DB as well as in our Entities, is it possible to have JPA, EclipseLink, or GlassFish ...

@Id @GeneratedValue but set own ID value

I have a table with a generated id, but in some cases I would like to set it on my own. Can I, somehow, force Hibernate to ignore the @GeneratedValue? ...

EntityManager injection results in NullPointerException

Hi, I'm writing my first JEE (EJB + Servlets etc.) application (please note: I'm using Eclipse). I'm stuck with a problem with EntityManager injection not working, and having some difficulties finding why due to my JEE (and Java in general) noobness. Here is my persistence.xml file - I think this is mostly correct, since I can launch th...

use of entityManager.createNativeQuery(query,foo.class)

I would like to return a List of Integers from a javax.persistence.EntityManager.createNativeQuery call Why is the following incorrect? entityManager.createNativeQuery("Select P.AppID From P", Integer.class); specifically why do I get "...Unknown entity: java.lang.Integer" Would I have to create an entity class that has a single fi...

How to detect open database connection with Hibernate / JPA?

I am learning JPA w/Hibernate using a Java SE 6 project. I'd simply like to be able to detect if the connection between Hibernate and my database (MS SQL Server) is open. For example, I'd like to be able to detect this, log it, and try reconnecting again in 60 seconds. This is what I thought would work but isOpen() doesn't appear to be ...

Looking for a tutorial and/or example for the following: Annotation based Spring 3 with JPA and/or hibernate

I want to learn Spring. I'd like to start with Spring 3. I want a simple tutorial and/or example. So no full blown web example please. Also - not a trivial example - so something incorporating persistence (e.g. JPA or hibernate) would be nice. Also - I don't want to get bogged down writing XML. So - Annotation based Spring 3 with JPA an...

@Basic(fetch = FetchType.LAZY) does not work???

Hello, I use JPA (Hibernate) with Spring. When i want to lazy load a Stirng property i use this syntax: @Lob @Basic(fetch = FetchType.LAZY) public String getHtmlSummary() { return htmlSummary; } But when i look at the sql that hibernate creates, it seems this property is not lazy loaded? I also use this class org.hibernate.tool.i...

Storing Objects in columns using Hibernate JPA

Is it possible to store something like the following using only one table? Right now, what hibernate will do is create two tables, one for Families and one for people. I would like for the familymembers object to be serialized into the column in the database. @Entity(name = "family") class Family{ private final List<Person> famil...

JPA Detected reentrant flush

I have little problem with openjpa implementation of jpa with spring 2.5. My dao method: @Transactional public User getUserByName(final String name) { return (User) getEntityManager().createQuery("select u from User as u where u.name = :name").setParameter("name", name).getSingleResult(); } returns org.springframework.dao.InvalidD...

Hibernate - How to cascade deletes using annotations where only unidirectional child relationship is specified

Supposing I have two entities a parent object and a child. I want the child to have a relationship specified to the parent entity and a reference, but I don't want the parent to have to know about it. The reason for this is there are numerous such relationships and explicitly specifying the relationship for all these children will mean...

openJPA on Java SE

Hi guys, I try to develop JPA project on ibm RAD. And i can run it on Webpshere successfully, but the problem is my machine is quite old. So deploying in JEE container isn't reasonable.And i want to run it on JSE.But it gives following error: 94 test INFO [main] openjpa.Runtime - Starting OpenJPA 1.2.1-SNAPSHOT 235 test INFO [m...

JPA/Hibernate with Oracle Label Security

I have an application built with Spring and JPA/Hibernate that is working very well, but I now have a requirement to add Oracle Label Security. This will require the creation of a proxy user assigned with certain roles in addition to the actual user. I am unclear what goes into persistence.xml and what goes in code. Also, if we want to g...