jpa

Jpa, Seam updating entity

Hi there, I've got a Stateful Session bean where I create a object (in this case a user object) and saving it in my db. Now I just want so update this entry which doesn't work - a NullPointerExceptionis thrown instead. What is my fault here? Bean @Stateful @Scope(ScopeType.SESSION) @Name("Userdata") public class UserdataBean implement...

Storing a hash as byte array with JPA

My User entity class contains password hash field, which is a byte array with a fixed length (32 since it's an SHA-256 hash). @Entity public class User { @Column(nullable=false) private byte[] passwordHash; ... } As you can see, I haven't annotated it with anything special, just a NOT NULL. This works, but will it perform...

Deep copying of EJB Entity beans with relations

What I have is an entity bean e.g. Entity (EJB 3) that keeps same type children in an ArrayList<Entity>, his parent <Entity> and a relation to another entity <Users>. Users can own many Entities, and vice-versa (many to many). What I would like to do is override Entity.clone() (or have a new method) to deep-copy Entity along with clone...

JPQL to query entity connected to another by @OneToMany

Has: class Container { @Id @Column(name="id") protected long id; @OneToMany @JoinColumn(name="container_id", nullable=false) protected Collection<Content> contents = new ArrayList<Content>(); } and class Content { @Id @Column(name="id") protected long id; @Column(name="link_id") protec...

How to stop handled Exceptions from being logged?

I have just implemented exception handling for a unique-constraint of a JPA entity. It is working as I want it to, but when triggered dumps the handled exceptions to the container logfile. A JPA entity is managed by a SLSB (Service Façade). The Service Façade is called from another SLSB, which provides remoting capabilities based on JA...

How to handle JPA Many-to-One Relation?

Hi, I am designing an application for collecting weather data. I have 2 POJO objects "Location" and "Record". Location contains information about latitude and longitude and the current weather conditions, and Record contains all the weather information over time for a specific location thus having a Many-to-one relation with Location. T...

Inherited abstract class with JPA (+Hibernate)

How would you configure annotations in the following example code? I'd like to stick with JPA annotations only and avoid Hibernate specific dependencies. Is the code below correct? @Entity public class RefExample extends RefData { } (There will be multiple versions of these classes, RefSomeOtherExample, etc, and one db table per clas...

How to use custom type in JPA column?

I have a class: public class Email { private String name; private String domain; public String toString() { return name + "@" + domain; } } I want to use it in JPA column: @Entity public class User { @Id private Integer id; private Email email; } This is what Hibernate says: org.hibernate.MappingException: Could ...

What's wrong with my custom type for JPA/Hibernate?

My custom type is (no default constructor!): package com.XXX.common; public class Email implements Serializable { private String e; public Email(String str) { e = str; } } My entity in Hibernate 3.5.6: package com.XXX.persistence; import com.XXX.common; @Entity @TypeDef( name = "email", defaultForType = Email.class, t...

Using Hibernate/JPA Event Listener to update one entity when other entities are updated.

Hi, I have three entities in my system - one of which must be updated when fields on the other two are changed: @Entity public class Order { private String name; private Integer quantity; private String status; } @Entity public class OrderLocation { private String status; private String desc; } @Entity public cla...

Transfer objects only once via EJB / JPA(Hibernate)

Hello! I am using the Java Enterprise Edition with JPA(Hibernate) for a Server-Client application (via EJB). The program stores a lot of data in a database that needs to be transfered to the client. Because I want to transfer as less data as possible I do not want to transfer objects twice. I want to demonstrate my problem with a small...

Applying annotations to fields inherited from @MappedSuperclass

Has: @MappedSuperclass class Superclass { @Id @Column(name = "id") protected long id; @Column(name="field") private long field; } and @Entity class Subclass extends Superclass { } How to annotate inherited id with @GeneratedValue and field with @Index within Subclass? ...

JPA: how to make a field auto increment

I use Eclipselink as my JPA provider, how can I make a field auto increment? ...

Complex reports with JPA and JasperReports

I have been reporting with jasperreports and JPA, all this reports are just "catalogs" in which the only information is an entity or some times an entity with it's related entities. Now i have to design reports with very complex information (grouping, summarization, fields not part of an entity and so on) which is not possible with my e...

Is LockModeType.PESSIMISTIC_WRITE sufficient for an UPSERT in JPA?

I've read this article on JPA concurrency, but either I am too thick or it is not explicit enough. I am looking to do a database-controlled atomic update-if-found-else-insert operation (an UPSERT). It looks to my poor slow brain that I can--within a transaction of course--run a named query with a lock mode of PESSIMISTIC_WRITE, see if ...

Problem using JPA with Oracle and grouping by hour

Hi, I have a problem using JPA with Oracle and grouping by hour. Here's the scenario: I have an entiry named EventData. This entity has a java.util.Date field named startOfPeriod. This field maps in a table field of datatype DATE. The query I'm using is something like: select min(ed.startOfPeriod) as eventDate, (...) from Event e inner ...

How do you set ANSI_NULLS off using JPA?

I'm trying to use one Named EntityQuery that will allow nulls in the Where clause using '=' Is there a way of setting ANSI_NULLS off or "set ANSI_NULLS off" in JPA the same way as in SQL? My JBOSS Data source file looks like the following: <?xml version="1.0" encoding="UTF-8"?> <datasources> <local-tx-datasource> <jndi-name>jdb...

Problem Deploying Wicket/JPA (EclipseLink) App to Glassfish

Hi, I have a small Wicket app that I can deploy to Glassfish v3 without any problems. I also have a JAX-RS webservice that includes a jar file that contains JPA entity beans and stateless service beans that deploys successfully. However, when I try to deploy a different Wicket application that makes use of the same entity/service jar,...

Upgrade Glassfish v2 to JPA 2.0?

Hi, I'm trying to use Hibernate 3.5.5 with Spring HibernateJpaVendorAdapter on Glassfish V2 but I'm getting the following exception when the Spring context is initialised: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode; at org.hibernate.ejb.util.LogHelper....

Complex queries with JPA criteria builder.

Can some one suggets me how to build up following query using JPA Criteria builder api. SELECT id,status,created_at from transactions where status='1' and currency='USD' and appId='123' order by id Its better if i can find a solution which creates dynamically based on the parameters given as a map using metamodel classes or any ot...