jpa

Implementing MVC when using JPA

Hi! As I have understood MVC, the logic for the model should also go into model itself - making every object a selfcontained entity. This means that the methods of an class has to have triggers and chains of actions. For example, by using setZipCode(zip) in a Person class could trigger an action where it looks up the zip code from a zip...

Updating JPA entity with reflection does not work?

I have an entity which looks something like this: (I'm coding to the web page so I apologize for any mistakes) @Entity public class Entity { @Id private Long id; private String field; // Insert getters and setters here... } I try to manipulate it using reflection: Long id = 1; Entity entity = myDao.getEntity(id); e...

How can I serialize a jpa bean that will also get the lazy loading relationship?

I need to serialize the result of a jpql query (meaning I need to serialize all the jpa beans). I want to get all nested relationship (even if they are lazy loaded) so that the client can deserialize on the other end without getting error. Is there a way to do that? ...

Hibernate property based on sum

I have figured out that I can use hibernate to get the sum of a number of entities using HQL as follows... public Long getEnvelopeTotal(AbstractEnvelope envelope) { String query = "select sum(t.amount) from User_Transaction t"; Long result = (Long) hibernateUtil.getSession().createQuery(query).uniqueResult(); return result; ...

How to make a java project from a Websphere ear work with JPA

Hi, I have an EAR installed in Websphere 6.1. Development is done in Eclipse, but using a simple Java project and updating the *.java and *.class files directly to the server. I want to start using JPA, but the @Stateless annotation gives the error "cannot be resolved to a type". What am I missing? Thank you for your time, Iulia ...

With Eclipselink/JPA, can I have a Foreign Composite Key that shares a field with a Primary Composite Key?

My database has two entities; Company and Person. A Company can have many People, but a Person must have only one Company. The table structure looks as follows. COMPANY ---------- owner PK comp_id PK c_name PERSON ---------------- owner PK, FK1 personid PK comp_id FK1 p_fname p_sname It has occurred to me that I could remove PER...

Why is hibernate open session in view considered a bad practice?

And what kind of alternative strategies do you use for avoiding LazyLoadExceptions? I do understand that open session in view has issues with: Layered applications running in different jvm's Transactions are committed only at the end, and most probably you would like the results before. But, if you know that your application is runn...

Defining the order of a list

Hi, I have the following problem. I have three classes, A, B and C. A contains a OneToMany relationed list of B:s. B contains a ManyToOne relation to C. C contains a field called "name" and B also contains a field called "name". What I'd like to accomplish is to have the items in A's list sorted primarily by C's name and secondarily by B...

Deep Copy in JPA

I would like to make a deep copy of an entity in JPA. I found an interesting discussion here: http://forums.java.net/jive/thread.jspa?messageID=253092&tstart=0 It sounded like the proposed solution was to set all @Id's to zero. Here's my basic code: //Start a JPA session. EntityManager em= emf.createEntityManager(); em.getTransa...

How to execute bulk delete with relationship in EJB3

I am trying to figure out how to execute a bulk delete on a @ManyToOne relationship without success. Scenario: Parent has many Downloads I want to execute a delete of all Downloads where the Parent date is > :some_date. I do not want to delete any of the Parent records, just the Download records. Download has a parent field that i...

JPA Writing from Multiple Process into Single DB

So, I've got a design question: I have several processes running that are updating my database. As an example, imagine a banking system, where I'm recording transfers from one account to another. In this case, I have to subtract the transfer amount from the source account and credit the same amount into the destination account as a singl...

Spring DaoSupport and @PersistanceContext EntityManager?

One of the most difficult things about understand Spring is that Spring supports multiple approaches to the same problem. So in my application I using injected EntityManager using the @PersistanceContext annotation, for example: @Repository public class JpaDao extends JpaDaoSupport implements Dao { @PersistenceContext(unitName = "...

JPQL and timestamp with timezone

I have the following field definitions in one of my JPA entities: @Column(nullable = false, name = "start_time", columnDefinition= "TIMESTAMP WITH TIME ZONE") @Temporal(javax.persistence.TemporalType.TIMESTAMP) private Date startTime = new Date(); @Column(nullable = true, name = "end_time", columnDefinition= "TIMESTAMP WITH TIME ZONE")...

Can javax.persistence.Query.getResultList() return null?

And if so, under what circumstances? Javadoc and JPA spec says nothing. ...

Drools Flow Persistence with MySQL (jpa, hibernate)

Needed steps for implementing Drools Flow Persistence with MySQL. I was following the Drools Flows Documentation on chapter 5.1.3.: Configuring Persistence.(https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/trunk/target/docs/drools-flow/html_single/index.html#d0e1157 ) Erroo-1: Caused by: bitronix.tm.utils.Propert...

JPA/Hibernate - Embedding an Attribute

I am having a trouble mapping an embedded attribute of a class. I have created some classes that are similar to what I am trying to do to illustrate. Basically, I have an @Embeddable class hierarchy that uses Inheritance. The top level class "Part Number" has only one attribute, and the extending classes add no attributes to the "Part...

Hibernate/JPA - Foreign Key Index in Object itself

I am currently working on 100+ Java Objects created by someone with no JPA/Hibernate experience into JPA Entities. Their Objects reference other objects based on a Foreign Key in the Class itself. All of the primary Keys are generated outside of the database. For Example (Just to Illustrate) Car @Entity @Table(name="CAR") public cla...

Can't enhance kodo JPA classes

I am just moving to Kodo JPA version 4.2 and it isn't going smoothly. when I run my any build script (in eclipse 3.4.1) I get BUILD FAILED D:\My Documents\eclipseWorkspaces\cnmp e341\blue ebig\ebig\src\java\build.xml:91: <openjpa-1.1.0-r422266:657916 fatal user error> org.apache.openjpa.util.MetaDataException: MetaDataFactory could no...

Spring JPA and persistence.xml

I'm trying to set up a Spring JPA Hibernate simple example WAR for deployment to Glassfish. I see some examples use a persistence.xml file, and other examples do not. Some examples use a dataSource, and some do not. So far my understanding is that a dataSource is not needed if I have: <persistence-unit name="educationPU" transaction-ty...

JPA HibernateSearch Projections

I'm trying to use JPA with HibernateSearch. I used Example 5.3 in http://docs.jboss.org/hibernate/stable/search/reference/en/html/search-query.html. The results come out as expected. However, the data coming back is a huge graph. I only need the primary key of the data. So, I tried Example 5.9, but it only shows the Hibernate API. ...