jpa

EJB3 mapped by? whose owning of OR mapping?

Hello everybody i wonder: when can i use mapped by to indicate whose is owing of relationship in one-to -one or one to many - or many to many relationship mapping with EJB3 (JPA) example i have two table A and B table A belong to table B so what i place mapped by for whose table? ...

JPA to retrieve name-value from child table without using model for child

This is something I'd really like to be able to do - resolve names based on id values without fetching the whole child model. Here is an example of what I have, a Table say Employee and a Name_Details table The Employee may look like this Create Table Employee { emp_idinteger not null generated by default as identity; -- generated pk...

Deleting JPA object fails due to foreign key constraints?

Why would the following query fail due to a foreign key constraint? There is no other way for me to delete the associated data that I am aware of. Query query=em.createQuery("DELETE FROM Person"); query.executeUpdate(); em.getTransaction().commit(); The I believe the offending relationship causing the problem is the activationKey fiel...

How do I do a JPQL SubQuery?

It is possible to do the equivalent of this sql query in JPQL? SELECT * FROM COUNTRIES c WHERE COUNTRY_ID IN ( SELECT DISTINCT COUNTRY_ID FROM PORTS p WHERE p.COUNTRY_ID = c.COUNTRY_ID AND STATE = 'A' ) ...

JPA: question on impedance mismatch in OneToMany relations

I have a question about JPA-2.0 (provider is Hibernate) relationships and their corresponding management in Java. Let's assume i have a Department and an Employee entity: @Entity public class Department { ... @OneToMany(mappedBy = "department") private Set<Employee> employees = new HashSet<Employee>(); ... } @Entity public clas...

How to Assign a JPQL query to a simple Java object?

I need to assign the result of a jpql result to a simple class java object I have something like this class myObject() { @id private Long id; private String Name; private String description; ... //getters and setters } I need to somehow to store the result of this SQL query, example // could be anytable SELECT DISTINCT c.table_i...

Query Google App Engine Datastore with Key.Id

I'm deploying a simple Java app to Google App Engine. I have a simple JPA Entity containing a Key as my generated ID. import javax.persistence.*; @Entity public class MyEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private com.google.appengine.api.datastore.Key key; ... Once I persisted this ob...

Disable automatic versioning in Hibernate JPA provider?

Hi, We are in a middle of an migration process of converting EJB2.1 entity beans to EJB3 we have chosen Hibernate as JPA 1.0 provider in Weblogic. We would like to disable auto. increment of entity version when persisting. Is it possible to turn of this feature? (as in property or persistence.xml?) Do JPA 1.0 support pessimistic lo...

Foreign key problem in Java Persistance API with Netbeans 6.9.1

Hi All, I have an error in setting up Java Persistence in Netbeans. I have used MySQL as Back-End Database Server. My Code is as below, Database CREATE TABLE `hub` ( `hub_ID` INT(11) NOT NULL AUTO_INCREMENT, `hub_Name` VARCHAR(45) NOT NULL, PRIMARY KEY (`hub_ID`), UNIQUE INDEX `hub_Name` (`hub_Name`) )ENGINE=MyISAM CREATE TABLE...

Bulk Delete ManyToMany collections on Derby

I'm using Hibernate and Derby. I've this class: public class Sensorboard { //... @ManyToMany(fetch=FetchType.LAZY) @JoinTable(name="SENSORBOARD_SENSORBOARD_JOIN", joinColumns= @JoinColumn(name="SENSORBOARD_ID", referencedColumnName="ID"), inverseJoinColumns= @JoinColumn(name="NEXTSENSO...

Loader constraint violation in hibernate createFullTextQuery

I have a webapplication using Hibernate and Jpa and want to add search via hibernate-search. I use the following hibernate versions: hibernate-core-3.3.2.GA hibernate-annotations-3.4.0.GA hibernate-entitymanager-3.4.0.GA hibernate-search-3.2.1.Final And for lucene: lucene-core-2.9.3 The following code compiles perfectly fine: public Li...

JPA 2 Remote Criteria?

Is there any way that Criteria for qureies can be built on a remote (Swing/SWT etc) client? We've been using the DetachedCriteria functionality in Hibernate for quite some time, but would like to use standard JPA 2. If not, could the code from hibernate be re-factored to create the remote API? Or is this something that might come alon...

Can reference to javax.persistence.EntityManager be cached?

Can we cache reference to EntityManager. As for our requirement, instead of injecting EntityManger into other EJBs, we are having utility class which will return the reference to entitymanager. The issue is each time we need to get reference, we are doing JNDI lookup. in order to avoid JNDI lookup, we want to cache the reference to ent...

JPA support for XML datatype columns

For a new project we are starting (which uses JPA 2 on top of Hibernate 3) we need to be able to store XML documents and then query on their content and structure at a later date. The databases we would like to support are DB2, Oracle and SQLServer. I know all three DB vendors support native XML querying (using SQL and XQuery like state...

Using JPA and JSON serialization

Hello, I would like to have a JPA Entity that has a GSon Object as a field/attribute. For instance: @Entity public class MyEntity { private JsonObject myObject; public JsonObject getObject() { return myObject; } public void setObject(JsonObject obj) { myObject = obj; } } I'm not familiar with ...

SINGLE_TABLE inheritance strategy using enums as discriminator value

Is it possible to use an enum as a discriminator value when using SINGLE_TABLE inheritance strategy? ...

Detach JPA objects with lazy initialized properties

There are two JPA entities: User and Order with one-to-many relationship. /** * User DTO */ @Entity @Table(name="user") public class User implements Serializable { private static final long serialVersionUID = 8372128484215085291L; private Long id; private Set<Order> orders; public User() {} @Id @GeneratedValue(s...

Can someone point me to a particularly good resource on JPA/Hibernate lazy/eager fetching?

Looking for a really good article that includes strategies/bugs/workarounds. I would prefer a pure JPA solution but I know Hibernate offers a lot of extensions. ...

JPA/Hibernate with optimistic locking and EHCache. Dirty checking interceptor not working properly.

Hi, folks. I am working on a JPA setup with optimistic locking (@Version) and EHCache. The underlying provider is Hibernate. I hooked a HibernateDirtyCheckInterceptor (extends EmptyInterceptor) into the Spring config file. This part is working, as my log entries get posted. My entity class clearly defines itself as not dirty, and the fi...

Overwrite Spring Roo Entity method

I'm working with Spring Roo and I need to overwrite Roo's Remove() method in the Roo_Entity.aj file. I'm getting a lot of Foreign Key constraint errors when I try to delete my entity, although I think my JPA annotations are correct. What I'm trying to do is overwrite the Remove() method in the Roo_Entity.aj file, to manually check for ...