Ado | 25 Jul 12:53 2014

conditional join clause

Hi, I would like to ask for help with creating query from criteria api, but
I want to simulate the conditional join clause from standard SQL, for

"from VOUCHER v left join USER_VOUCHER uv on ((v.VOUCHER_ID =
uv.VOUCHER_ID) and uv.USER_ID=2).."

More info:

I have two entities mapped to tables

 <at> Entity
 <at> Table(name = "voucher")
public class Voucher implements Serializable {
    private static final long serialVersionUID = 1L;
     <at> Id
     <at> GeneratedValue(strategy = GenerationType.IDENTITY)
     <at> Basic(optional = false)
     <at> Column(name = "VOUCHER_ID")
    private Integer voucherId;
     <at> Column(name = "VOUCHER_NAME")
    private String voucherName;
     <at> OneToMany(mappedBy = "voucherId")
    private Collection<UserVoucher> userVoucherCollection;

    public Voucher() {
//rest ommited

(Continue reading)

Marc Logemann | 24 Jul 23:05 2014

MariaDB vs. MySQL


i am fighting weird issues with an openjpa application on MariaDB while all
these are non existant on MySQL. Things like "fetch join" are just
different or better said with openjpa 2.2.0 and MariaDB problematic in some

I even see different SQLs being created from the same JPAQL Queries. Is
this possible at all?

Thanks for infos.
Kalpa Welivitigoda | 20 Jul 20:14 2014

Create H2 database even before adding records


I am developing an application with H2 in memory database.

The issue is that the table is created only after I add a record. Before
that, if I search for a record it says that the table is not found. I want
to create the table at the time the application starts rather than waiting
for a record to be added. Is there any property that serves this

Following is the content of persistence.xml,

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="" version="2.0">
    <persistence-unit name="rest-jpa">

            <property name="openjpa.jdbc.SynchronizeMappings"

I have the datasource defined in context.xml as follows,

<?xml version="1.0" encoding="UTF-8"?>
(Continue reading)

artaxerxe | 15 Jul 13:39 2014

Problems with OpenJPA when deploying in Apache Servicemix and Spring. (OSGi environment)

Hello everyone. For a time I'm striving with a problem that I have with
OpenJPA. I'm trying to deploy my bundle that contains OpenJPA entities in an
OSGi compliant server, namely Apache Servicemix. I'm accessing the OpenJPA
entities using Spring. The problem is that when I make the deployment for my
bundle, I get this error:

openjpa.Runtime - An error occurred while registering a ClassTransformer
with PersistenceUnitInfo: name 'openjpa-test', root URL [bundle://240.0:1].
The error is logged along with this warning. Load-time class transformation
will not be available.<openjpa-2.3.0-r422266:1540826 nonfatal general error>
org.apache.openjpa.util.GeneralException: Resource does not exist:
(Continue reading)

Mansour Al Akeel | 12 Jul 13:03 2014

Problem creating table with <at> IdClass an foreign keys constraints

Hello all,

To demonstrate the problem and make it easier to get help, I have created
an application here:

This application is to create tables with constrains from JPA entities.
Tables are created, however I am unable to generate
the foreign key constrains.

Here's the description of the entities. We have the Services Entity, with
fields relates the service provider to the
client, and the service type. The Service Entity has its primary keys
(service provider and client). Both are Person(s).

When this application is run using  <at> IdClass(ServicePK.class), I get the

<openjpa-2.3.0-r422266:1540826 fatal user error>
org.apache.openjpa.persistence.ArgumentException: The id class specified by
type "class com.example.Service" does not match the primary key fields of
the class.  Make sure your identity class has the same primary keys as your
persistent type, including pk field types. Mismatched property: "client"
(Continue reading)

David Minor | 11 Jul 02:09 2014

Re: Avoiding N+1 on collection in recursive relation

The problem seems to be that in org.apache.openjpa.jdbc.sql.SelectImpl, as
it's building up the necessary select statements, it keeps a HashSet of the
fields that already have eager selects created for them, and doesn't create
another eager select if one already exists for that particular field.

So, when requesting a particular entity of class A { List<B> bs; List<A>
children; }, OpenJPA creates parallel eager selects for '' and
'A.children', but then as it examines 'children', it doesn't create a
parallel eager select for their 'bs' since the field '' already has an
eager select for it according to the HashSet.

Later as it's loading the data it uses individual statements to get the
missing data.

There's a comment in JDBCStoreManager prior to the call to

// create all our eager selects so that those fields are reserved
// and cannot be reused during the actual eager select process,
// preventing infinite recursion

which makes sense, since you wouldn't necessarily want to select the
children's children's children, etc. But in this case, it seems to prevent
efficient selection of desired fields.

I believe this is also the cause of the problem reported in

In that case you have class A { List<B> list1; List<B> list2; }, and eager
selects are created for list1's collection fields but not list2 (since both
(Continue reading)

Rick Curtis | 10 Jul 14:58 2014

Re: Avoiding N+1 on collection in recursive relation

David -

It seems like this question has been asked numerous times on this mailing
list and no one has come up with a good answer. I too don't have an answer,
but if you come up with anything please post back to the list.


On Tue, Jul 8, 2014 at 6:56 PM, David Minor <daveminor@...> wrote:

> I have an entity (A) that has a recursive OneToMany relation with itself
> (children). A also has a OneToMany relation to entity B.
> Whenever A is fetched, the queries to fetch B for entity A and its children
> are all separate queries.
> Is there any way to avoid this?
> --
> _____________
> David Minor


*Rick Curtis*
michaelwiles | 10 Jul 14:16 2014

OrderColumn not working in one to many with mappedBy

I have a "regular" one to many. It has an OrderColumn annotation.

This mapping when I run my tests I see the order column called
elementsWithOrder_ORDER getting updated.

However, the following mapping (with a mappedBy) I don't see the order
column being updated...

The mappedby field looks as follows:

If you switch the persistence provider to Eclipselink the tests pass.

I have created a  github project
<>   to demonstrate this.

I'm assuming this is in fact a bug because surely using "mappedBy" shjould
not stop ordered lists from working.

Btw, this is run on OpenJPA 2.3.0

View this message in context:
Sent from the OpenJPA Users mailing list archive at

David Minor | 9 Jul 01:56 2014

Avoiding N+1 on collection in recursive relation

I have an entity (A) that has a recursive OneToMany relation with itself
(children). A also has a OneToMany relation to entity B.

Whenever A is fetched, the queries to fetch B for entity A and its children
are all separate queries.

Is there any way to avoid this?


David Minor
Pawel Veselov | 6 Jul 06:20 2014

Something is missing in OpenJPA 2.3.0 distribution


Something seems to be missing from the libraries in the OpenJPA distro.
I don't normally use the "all" jar, and without it, the enhancer fails with
class not found of org/apache/xbean/asm4/ClassVisitor.class. The class is
there in "all" jar, but not in any of the library jars...
Pawel Veselov | 6 Jul 05:58 2014

OpenJPA 2.3.0 packages Derby?


I see that 2.3.0 has a packaged derby jar (

I was wondering what the reason is, and can I yank it out even if I'm not
using Derby (in my deployment, derby.jar is deployed at application server
level, and openjpa is packaged along .war file)

Thank you,