jpa

Hibernate transform instance to subclass

Hi, I have mapped class in JPA. : @Entity @Inheritance(strategy = InheritanceType.JOINED) public class User { private Long id; private Long name; //getters and setters go here .... } I also have a subclass of this class, called Admin: @Entity public class Admin extends User { private String cridentials; //gett...

JPA Entity Manger Factory injection fails (JPA 2, Eclipselink, J2EE 6)

I am trying to get a small sample web app up and running but I have run into a problem injecting the Entity Manager Factory. My persistence.xml is as follows; <persistence version="2.0" xmlns=" http://java.sun.com/xml/ns/persistene" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java...

Hibernate / JPA: duplicates in child collection

My data model is made of Schools and Students. Students have a FK to the School they belong to. I do not understand why the collection contains duplicates, i.e. Joe, Joe, Mary, Mary, Tom, Tom, etc The SQL query generated by Hibernate is correct and does not return duplicates. I could implement a hack to filter out duplicates, but I am no...

Java Web Start application gives MARSHAL exception when data loaded from database via remote EJB.

I have a Java Web Start application calling remote Java EE 5 EJBs to load in data from a database. When the data is returned from the EJB to the client, I get the following exception. Looking it up online, it seems that everyone gets this exception and everyone has a different solution for it. All of my entities (abstract or not) imple...

How to prevent non-repeatable query results using persistence API in Java SE?

I am using Java SE and learning about the use of a persistence API (toplink-essentials) to manage entities in a Derby DB. Note: this is (distance learning) university work, but it is not 'homework' this issue crops up in the course materials. I have two threads operating on the same set of entities. My problem is that every way I have t...

question regarding mulitple entityManagerFactory in Spring 2.5.6

I am using Spring+JPA+Hibernate in my application. The issue I am facing is that I have multiple databases in my application and I have configured them correctly(I think) in the applicationContext.xml. Please refer to my applicationContext.xml below and tell me if: That's how I am supposed to configure the multiple databases If yes h...

Is it possible for hibernate to create the database and database user?

I have an application that uses hibernate and JPA to handle the database. I know that hibernate can create the database tables for me, however, I've found that I must first create the database files and the database user account before hibernate can create the tables. Is there a way for hibernate to do create the database and user accoun...

Memory leak with paged JPA queries under JBoss AS 5.1

Hi, guys, I'm trying to integrate Hibernate Search into one of the projects I'm currently working on. The first step in such an endeavour is fairly simply - index all the existing entities with Hibernate Search(which uses Lucene under the hood). Many of the tables mapped to entities in the domain model contain a lot of records(> 1 milli...

JPA sequence for serial number

Hello, I wonder is there a clean (or native) way to generate sequence for a table, to use it as a serial number. It needs to be consecutive (1, 2, 3 ...etc), and avoid any possible race/transaction issues(if multiple user try to persist same time). It doesn't require to be the primary key. @Id private Long id; private Long...

What is the correct usage of the Seam @Transational annotaion?

I'm a bit confused about the meaning of values used in the @Transactional annotation, specifically @TransactionPropagationType. Perhaps Gavin thought it would be obvious enough from the name of each enum type and decided not to document the actual meaning... Be that as it may I have no clue what any of the following actually mean: MANDAT...

Backup a database using JPA (Design)

I have a working code that doesn't work always. Here's my approach: Creating the backup Create Entity Manager for source database Create Entity Manager for destination database (embedded Derby Database) Copy entities (Select all entries of a table (table order hard coded right now) and copy them to the destination database. Basically ...

When to use, not to use, OneToOne and ManyToOne

Hello, I just started reading of JPA, and the implementation in hibernate to understand the details. but, to continue with development till then, can you help to clarify a basic qn. When to use OneToOne I may use OneToOne if the entity manager needs to handle the persistency of the related object. the point is, I can always live wit...

JPA w/o application server

I'm just writing a small java application and I would like to be able to persist the data model in a database. So I was wondering if I could use JPA for this. I used JPA some time ago, but as far as I remembered it required an application server. So I'm wondering can I just JPA to persists my classes w/o using an application server. ...

@OneToOne annotation within composite key class is not working.

Dear Friends, Maybe somebody can clarify what is wrong with the code below. When I create one-to-one association within embedded class (it is composite primary key) like in the code below: @Entity public class Test { @EmbeddedId private TestId id; @Embeddable public static class TestId implements Serializable { ...

it's possible configure a persistence.xml for multiple data sources??

hi i just want to know how configure in a persistence.xml two datasources one of the data sources have a jar outside from the other. I'm tried but i really don't if it's possible ...

Combining JAXB and JPA in one model

I have to design a data model (in a Java EE 6 application) that will be persisted via JPA, and that also needs to be serialized via JAXB. The last time I did that, I had one group of entity classes with JAXB annotations, and another with JPA annotations. This meant that I had to have a lot of boilerplate code for translating between the ...

Dynamic Inheritance - Java

Dynamic Inheritance I have a situation where I want a class (which is a JPA entity) to be able to extend either class A or class B dynamically. My thought was to use Generics, but it looks like generics doesn’t support this. For example: @Entity public abstract class Resource() { ... } @Entity public abstract class Snapshot() { ... }...

configure spring to use my CM dbpool so I can inject the persistenceContext in my dao

background: I am using geronimo + hibernate + spring. Just using the JPA api's on an EJB backend that contains no servlets, no web.xml. I've been working on this for literally 41 days and have tried all types of combinations so now I'm asking on StackOverflow for help. Please bare with me I have not slept. I have a geronimo managed...

Guice dependency injection for entity beans?

For a rich domain driven design I want to use Guice dependency injection on JPA/Hibernate entity beans. I am looking for a similar solution as the Spring @configurable annotation for non-Spring beans. Does anybody know of a library? Any code examples? ...

JPA and unique fields

I have two persistence objects in my app: Things and tags attached to things. The app can generate collections of things with tags attached. Tag objects have a unique name (it doesn't make sense to tag something twice with the same tag). When inserting a Thing (with tag objects attached) some of these tag objects with the same name mayb...