jpa

What cache concurrency strategy should be used for @ManyToOne fields

What cache concurrency strategy should be used for @ManyToOne fields for a particular entity class. Would it make sense to use READ_ONLY instead of READ_WRITE, since these fields usually don't change after entity creation @ManyToOne(fetch = FetchType.LAZY) @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) ... private User user; ...

Calling next value of a sequence in jpa

Hello, I have a class mapped as an Entity to persist it in a database. I have an id field as the primary key so every time the object is persisted the value of the id is retrieved from the sequence "myClass_pk_seq", a code like the following one. @Entity @Table(name="myObjects") public class MyClass { @Id @GeneratedValue(strate...

Hibernate triggering constraint violations using orphanRemoval

I'm having trouble with a JPA/Hibernate (3.5.3) setup, where I have an entity, an "Account" class, which has a list of child entities, "Contact" instances. I'm trying to be able to add/remove instances of Contact into a List<Contact> property of Account. Adding a new instance into the set and calling saveOrUpdate(account) persists every...

How to create custom query for CollectionOfElements

Hi. I have problems creating a custom query. This is what entities: @Entity public class ApplicationProcess { @CollectionOfElements private Set defaultTemplates; //more fields } And Template.java @Embeddable @EqualsAndHashCode(exclude={"used"}) public class Template implements Comparable<Template> { @Setter priv...

JAXB Mapping cyclic references to XML

I have an object graph that contains a cycle. How do I get JAXB to handle this? I tried using the @XmlTransient annotation in the child class but the JAXB marshaller still detects the cycle. @Entity @XmlRootElement public class Contact { @Id private Long contactId; @OneToMany(mappedBy = "contact") private List<Contac...

Java: Difference betwen UserTransaction and EntityTransaction

Title says it all: What is the difference between a UserTransaction and a EntityTransaction? My rudimentary understanding is that UserTransaction is used when JTA is required (e.g. to do queries on mulitple things), and that EntityTransaction is used when JPA only is required (e.g. when the query is atomic). Is that the only difference...

How to detect entities automatically with openJPA?

I'm looking for an entity detection in OpenJPA. That I don't need to declare all entities in the persistence.xml. Edit: I'm sorry, I forgot to say that I develop a java se app. ...

How to map Hashtable component of a class, using JPA?

I have this class: public class DBRow { public String url; public String title; public static Hashtable<String, Integer> words; public Vector<String> keywords; } What I must do is store many instances of this class in a database. I'm using Hibernate and JPA to get the job done. Using JPA I've come so far (really not fa...

JPA/Hibernate conditionally onetomany relationship?

Hi, I am using Hibernate Tools to generate the DAO and classes straight from database. There are two tables (table A and B) in the database, and there is a one to many relationship from A to B (multiple rows in B mapped to single A). In the generated code of A (class A), there is a collection of class B, which reflects the one to many ...

Loading selected Hibernate entities with JPA & Spring

Is there a way to load only selected entities with Hibernate? I would like to only load a selected handful for integration testing. ...

JPA insert statement

What's the correct sintax of a JPA insert statement? This might sound like an easy question but I haven't been able to find an answer. I know how to do it from Java code but I'm looking for a way to insert objects into the database if the database was created. Any ideas? ...

Can I refer to the primary key of any entity in JPQL by the name "id", regardless of the entity's ID property name?

Hibernate allows you to just say ".id". Let's say I have: @Entity public class Customer { @Id private Integer customerId; @Basic private String customerName; // getters and setters } And I want to get the name of a customer by ID: SELECT cust.customerName FROM Customer cust WHERE cust.id = :customerId Notice I put "id" rathe...

Migrating procedural, antique CRUD code and proprietary DBMS to OO ORM on SQL

Please excuse my long-winded explanation, but I wanted to be as explicit as possible in the hopes of getting as much useful feedback on my situation as possible. You can skip to the questions at the bottom if you are impatient. Explanation At my current job, development is done in an antiquated language that is hard-wired to a proprie...

Liquibase diffChangeLog against a Hibernate mapping definition

Hi all, This question is related to "Hibernate using JPA (annotated Entities) and liquibase". I was actually wondering what to expect when doing a Liquibase diff against a Hibernate mapping definition. What it seems to produce: A liquibase changelog that migrates the state of my hibernate mappings to the current image of the database....

When entityManagerFactory is not named "entityManagerFactory" ...

My webapp contains many entityManagerFactories (DBs) , each has its unique name , such as entityManagerFactoryApp , entityManagerFactoryBusiness , entityManagerFactoryForum ...etc. In a webapp , I have to add OpenEntityManagerInViewFilter to achieve "Open Session in View" pattern. <filter> <filter-name>Spring OpenEntityManagerInVie...

Nothing inserted into triple join table; Hibernate

Please tell me, what am I doing wrong. I have this function: public String create(){ try { Iterator<Tag> it = tags.iterator(); List<Tag> tagList = new ArrayList<Tag>(); while(it.hasNext()){ Tag t = it.next(); if (projectsTags.contains(t.getName())) { ...

JPA/EclipseLink Returning No Results

I am new to Java and JPA. I am trying to connect to a database and return some results from a table, but when I run the query, I get an empty list as a result even though the table has over 100,000 rows. Here is my persistence.xml: <?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:...

JPA or Hibernate - Joining tables on columns of different types

Is there a way to tell Hibernate to wrap a column in a to_char when using it to join to another table or conversely convert a NUMBER to a VARCHAR? I have a situation where I have a table which contains a generic key column of type VARCHAR which stores the Id of another table which is a Number. I am getting a SQL exception when Hibernate ...

EclipseLink Document Doesn't Explain "session"

I am trying to execute a query using EclipseLink following the crappy documentation at http://wiki.eclipse.org/Introduction_to_EclipseLink_Expressions_%28ELUG%29, but every time you need to execute an Expression it uses a variable called "session", but no where does it explain where this "session" variable comes from. I already have a pe...

JPA inserts slow with an object graph

I'm trying to do a cascading save on a large object graph using JPA. For example (my object graph is a little bigger but close enough): @Entity @Table(name="a") public class A { private long id; @OneToMany(cascade = CascadeType.ALL, mappedBy = "a") private Collection<B> bs; } @Entity @Table(name="b") public class B { private lo...