jpa

JPA Native Query for Entity with Inheritance

I have an entity class and a subclass based on that entity: @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public class A and @Entity public class B extends A I need to issue a native query that uses a stored procedure on the base class (A) only. If I attempt it as follows: entityManager.createNativeQuery("selec...

How to check if an JPA/hibernate database is up with second-level caching

I have a JSP/Spring application using Hibernate/JPA connected to a database. I have an external program that check if the web server is up every 5 minutes. The program call a specific URL to check if the web server is still running. The server returns "SUCCESS". Obviously if the server is now, nothing is returned. The request timesout a...

jpa one-to-many persist children with its ID

Hi, I have a eneity: @Entity public class Item { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column private Long id; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "item") private List<Feature> features= new ArrayList<Feature>(); The Children Entity: public class Feature{ @Id @Generated...

Problem with Hibernate find method

UPDATE: EXAMPLE TO CLARIFY I'm going to put an example of what's happening just to clarify the situation in my Spring + Hibernate application. Imagine I have this two entities (suppose getters and setters exists too) @Entity public class Class1(){ private Integer id; @OneToOne private Class2 object2; } @Entity public class Clas...

hibernate3 maven plugin:make hbm2java generate hibernate annotations instead of ejb3 annotations

Is there a way of forcing the hbm2java goal of hibernate3 maven plugin to generate java classes with hibernate annotations instead of ejb3 annotations? I really do not need ejb/jpa, and hibernate annotations would suit me better because of the better integration with grails. ...

JPA ManyToMany relationship issue

I am developing human task engine based on WS- Human Task spec. When handling people assignments in task, there are several roles specific to task. For a task we have stakeholders, potential owners, business administrators and notification recipients. So when reflecting this in my domain objects, I designed it using several Sets like fol...

Using reserved JPQL keywords with JPA

I have an entity class called "Group" and NetBeans warns me "The entity table name is a reserved Java Persistence QL keyword". A similar case would be the use of reserved SQL keywords. Will this name be escaped? Would the use of a different table name solve the problem @Table(name="otherName"). Or should I rename the class? ...

Why does JPA have a @Transient annotation?

Java has the transientkeyword. Why does JPA have @Transient instead of simply using the already existing java keyword? ...

Why delete-orphan needs "cascade all" to run in JPA/Hibernate ?

Hello, I try to map a one-to-many relation with cascade "remove" (jpa) and "delete-orphan", because I don't want children to be saved or persist when the parent is saved or persist (security reasons due to client to server (GWT, Gilead)) But this configuration doesn't work. When I try with cascade "all", it runs. Why the delete-orphan ...

ORM for Lift: Mapper or JPA?

Hi everybody, I'm creating a small application for my company in Lift. I'm quite a newbie in Scala/Lift so I'm using this chance to practice. Now, I have a question on what ORM system to use. On one hand, Mapper is the Lift default. On the other hand, I've read it's not good in certain areas and will be replaced by Record (which is not...

How do I use JPA to make library objects database persistent?

I've been using JPA on a small application I've been working on. I now have a need to create a data structure that basically extends or encapsulates a graph data structure object. The graph will need to be persisted to the database. For persistable objects I write myself, it is very easy to extend them and have the extending classes als...

checks for constraint violation before persisting an entity

What is the best mechanism for preventing constraint violation checks before creation | modification of an entity? Suppose if the 'User' entity has 'loginid' as the unique constraint, would it be wise to check if there is an user entry already with this loginid name before creation or modification. OR Would you let the database throw...

Django-like queries in Java/JPA

Is there any library or framework to make JPA queries in a less verbose way such as: User.query("age < 30") instead of: Query query = entityManager.createQuery("select u FROM User u WHERE age < 30"); return query.getResultList(); I suppose there is no standard way to do it with JPA. I've seen Hibernate Criteria API, that is not as...

JSF + Spring + JPA + Hibernate: keep entitymanager alive when rendering view?

Totally new to Spring & Java development but working on a project for a class with some experienced developers. I believe we're using Spring MVC as our web layer(but I'm a C# guy so I may be mistaken in that regard). We have a view that gets an object with lazily loaded properties -- pretty straightforward stuff. Yet when I call one o...

JPA Secondary Table Issue

I have a three tables: User, Course, and Test. Course has a User foreign key and Test has a Course foreign key. I am having trouble mapping the Test collection for each User since I need an intermediary step from User -> Course -> Test. I am trying to use a SecondaryTable since the User key for the Test is its associated Course row. A...

org.hibernate.MappingException using annotations

I am using JPA annotations for these two classes: @Entity @RooJavaBean @RooToString @RooEntity @MappedSuperclass public abstract class BaseEntity { @Temporal(TemporalType.TIMESTAMP) @DateTimeFormat(style = "S-") private Calendar created; @Temporal(TemporalType.TIMESTAMP) @DateTimeFormat(style = "S-") private Calendar updat...

Is it possible to mix orm.xml definitions with annotations when using JPA/hibernate ?

I'm working on an application whihc supports using several DB vendors, with the table definitions being different for each DB type. The trouble is that the column definitions are not what hibernate expects, and so my entities contain a lot of @Column(..columnDefintion="..."...) annotations. To further complicate the issue, there's no wa...

Hibernate (JPA) cascade - retrieve id from child

I have a parent class with the following field with cascading option: public class Parent { @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL) @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN) private final Set<Child> children = new HashSet<Child>(); public addChild(Child child) { children.add(child); } } I...

Modelling a Two to Many Relationship in JPA/Hibernate

Hi folks, I have the following entity relationship problem. A "Game" must have two (and only two) "Team" objects. A "Team" can have many "Games" This, as far as I can see is a Two-to-Many relationship. However...I don't know how to model this in JPA. Eg, I was going to do something like this... @Entity public class Team extends BaseOb...

Deleted entity passed to persist exception

Hi, I have this kind of entities: Document | n .. to ..1 | DocumentType | 1 .. to .. n | PropertyType | 1 .. to .. n | DocumentProperty I simply try to remove a document like: entityManager.remove(document); but an error is firing: 16:45:51,499 ERROR [[Seam Resource Servlet...