jpa

Map a list of strings with JPA/Hibernate annotations

I want to do something like this: @Entity public class Bar { @Id @GeneratedValue long id; List<String> Foos } and have the Foos persist in a table like this: foo_bars ( bar_id int, foo varchar(64) ); UPDATE: I know how to map other entities, but it's overkill in many cases. It looks like what I'm s...

InnoDB deadlock with read-uncommited! - Java - Glassfish - EJB3 (JPA/Hibernate)

Hello I'm new here and need some help :) It's been several days that i got deadlock issues on a Java application with Glassfish - EJB3 with Mysql InnoDB Config: Mysql InnoDB: Ver 14.12 Distrib 5.0.51a, for debian-linux-gnu (i486) using readline 5.2 Application server: Glassfish v2.1 Persistance with EJB3 - JPA - Hibernate To make i...

Foreign key is also part of the primary key

Is it possible in plain JPA or JPA+Hibernate extensions to use a foreign key that is also part of the composite primary key? @TableGenerator(name = "trial", table = "third", pkColumnName = "a" , valueColumnName = "b", pkColumnValue = "first") @Entity public class First{ @Id @GeneratedValue(strategy = GenerationType.T...

Need help with design structure and looking up EntityManager and UserTransaction in helper's helper

Hi there, I am basically a newbie whose starting work on a new webapp. The webapp is mostly your basic CRUD operations. For this, I have decided to use JPA with Hibernate as the Persistence provider and will be developing on Apache Derby for development and testing purposes. I am using GlassFish v2 as the App Server to deploy my EJB3 be...

Splitting Hibernate Entity among 2 Tables

I have a simple Class Hierarchy that I am trying to get to work with Hibernate/JPA. Basically what I want is for the MovementData to be in its own Table with a FK to the integer id of the Main Vehicle Table in the Database. Am I doing something wrong? How else can I accomplish something similar? I am pretty sure I am following the JPA...

EJB3 - handling non-standard link tables.

Hi all, I have a situation where I am working with EJB3 and a legacy database. I have a situation where there is a many-to-many relationship between two tables A and B, defined through a third (link) table L. The complication is that the link table has other fields in it other than the PK's of tables A and B. The columns are standard t...

JPA EntityManger preforming a database insert on merge?

I am using JPA with Hibernate underneath, and I am having trouble getting merge to work, but before I describe the problems I am encountering with JPA, let me lay out what I am trying to accomplish, just in case my problems stems from my approach. I have data from on system that I need to place into another system. To do this I am read...

Hibernate: "Field 'id' doesn't have a default value"

Hi, all. I'm facing what I think is a simple problem with Hibernate, but can't get over it (Hibernate forums being unreachable certainly doesn't help). I have a simple class I'd like to persist, but keep getting: SEVERE: Field 'id' doesn't have a default value Exception in thread "main" org.hibernate.exception.GenericJDBCException: cou...

Do I want to minimize the scope of @Transactional?

Not sure if 'scope' is the correct term here. I am using Spring for JPA transaction management (with a Hibernate underneath). My method to preform database transaction is private, but since you can only set @Transactional on a class or on a public method Since this mechanism is based on proxies, only 'external' method calls coming i...

JPA Delete with 2 Interlocking Entity Classes

I have 2 EJB 3 Entity Beans: @Entity public class Organisation { @Id @Column(length = 64) private String guid; private String name; @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE) @JoinColumn(name = "home_unit_fk", nullable = true) private Unit homeUnit; } @Entity public class Unit { @Id @Column(len...

Spring + JPA (Hibernate) on Glassfish --> ClassVisitor problem

I'm trying to write a simple web app with Spring 2.5 (core + MVC) and JPA (using Hibernate for the persistence mechanism). Every time I deploy, I'm getting a "Class not found exception" that points to ClassVisitor. This is a known version problem with the asm library. In a stand-alone app, I can make sure that the proper asm version i...

How do I guarantee the order of items in a collection

I have a list of objects and each and every object in the list have a position which may not change unless explicitly changed, in other words, the objects are in a queue. What collection should I use in my entity class to store these objects and how should that collection be annotated? I currently have this @Entity class Foo { ... ...

Setting a JPA timestamp column to be generated by the database?

In my SQL Server 2000 database, I have a timestamp (in function not in data type) column of type datetime named lastTouched set to (getdate()) as its default value/binding. I am using the Netbeans 6.5 generated JPA entity classes, and have this in my code @Basic(optional = false) @Column(name = "LastTouched") @Temporal(TemporalType.TIM...

JPA not saving foreign key to @OneToMany relation

I'm using Spring with Hibernate as a JPA provider and are trying to get a @OneToMany (a contact having many phonenumbers) to save the foreign key in the phone numbers table. From my form i get a Contact object that have a list of Phone(numbers) in it. The Contact get persisted properly (Hibernate fetches an PK from the specified sequence...

Extending JPA entity mapping

I'm looking for an easy way to extend existing JPA mapping. The idea is as follows: I have an EAR project with EJB3+JPA module which has ClassA annotated and mapped to table class_a. But I want some other module (another EJB module) to have ClassB which adds more properties to ClassA (extend?). One way that I though about, is just to a...

how do i pass EntityManager to @PostUpdate

I want to save history of changes, so in @PostUpdate i want to create new instance of another entity and save it, how do i pass EntityManager to that method? ...

Transitioning from Castor to JPA

I am trying to make my java application more standards compliant and one of the biggest issues i am facing is transitioning our ORM framework from Castor JDO to a JPA implementation (thinking either Hibernate or DataNucleus). We have our own persistent data abstraction layer so the basic refactoring can easily be done by adding a JPA imp...

Good books or online resources for learning Hibernate

What I found so far are some online resources like this: http://www.torsten-horn.de/techdocs/java-hibernate.htm (GER) https://www.hibernate.org/5.html (Hibernate Docs) http://docs.jboss.org/hibernate/stable/core/reference/en/html/tutorial.html http://www.manning.com/bauer2/chapter2.pdf (Sample chapter of Java Persistence with Hiberna...

Saving bidirectional ManyToMany

I have two entity classes annotated in the following way @Entity class A { @ManyToMany(mappedBy="A", cascade=CascadeType.ALL) private List<B> b; .. } @Entity class B { @ManyToMany(cascade=CascadeType.ALL) private List<A> a; .. } If I store an instance of the class 'B', the relations are stored in the database and the g...

Why does Spring's @Configurable sometimes work and sometimes not?

I'm trying to use automatic dependency injection via Spring's @Configurable annotation w/ @Resource on the fields needing injection. This involved some setup, like passing spring-agent.jar to my JVM. For the full details see here. It works... mostly. When my Tomcat is booting up, I see the AspectJ init messages, my User objects automati...