Hal Hildebrand | 28 Mar 00:28 2015

OpenJPA PostgreSQL UUID column

Attachment (UuidValueHandler.java): application/octet-stream, 2111 bytes

I’m trying to use the native UUID type for PostgreSQL in my OpenJPA model.  I’m using OpenJPA 2.3.0 and at the current level of the PostgreSQL JDBC driver.

I’ve tried to accomplish this several times and I’ve gotten a bit further this time.  I created a ValueHolder (see attached file) and it does what I believe is the correct setup for this type.  I use this as the strategy for the column - i.e. :

<at> Strategy("com.chiralbehaviors.CoRE.openjpa.UuidValueHandler")

I’ve validated via breakpoint that the UuidValueHolder is indeed called in setup and when converting values.  I’m at the point of trying to do an insert, and regardless of whether I use an actual UUID as the return mapping (i.e. no transform) or a string (UUID.toString()) I get the same error:

ERROR: column "id" is of type uuid but expression is of type bytea
  Hint: You will need to rewrite or cast the expression.
  Position: 93 {prepstmnt 1848199707 
INSERT INTO ruleform.agency (id, notes, update_date, description, name, 
    VALUES (?, ?, ?, ?, ?, ?) 
[params=(byte[]) [B <at> 9ac8b5b, (null) null, (Timestamp) 2015-03-27 15:20:05.921, (null) null, (String) CoRE, (byte[]) [B <at> 15b17c95]} [code=0, state=42804]

I believe that this error comes from the postgres jdbc driver, not openJPA.  I’ve even tried using PGObject, which surprisingly works just fine, but throws the same error.

In my google searches, this has come across as a typical problem, and I’ve only found solutions for this (hypothesized) for Toplink and Hibernate.  The one thing I could find suggested writing the ValueHolder and that does work up until the point I try to actually insert in JDBC land.

Note that the UUID is being passed as a byte array.

So my question is, am I doing anything incorrect?  Missing something?  From the error message, it would appear postgresql wants me to cast the result, but I’m not sure how to accomplish that in OpenJPA.  It could simply be a red herring.

Any help appreciated, as I simply can’t find a working solution via Der Google

sia | 17 Mar 23:55 2015

Forcing an outer join in many-to-one relations with order by column

Hello All:

I was wondering if someone can help me with this issue. I have been reading/searching the forum with no avail
as well all over the web. I have an entity as follows:

 <at> Entity
 <at> Table(name = "REQUEST")
public class Request {

 <at> ManyToOne(fetch = FetchType.EAGER)
     <at> JoinColumn(name = "SLOT_ID", referencedColumnName = "SLOT_ID")
    private Asset slot;


Running the following query cause a left outer join with my relation : 

Select r from Request r;

However; if I run

Select r from Request r ORDER BY r.slot.name

this would generate an inner join.

I would like to force an outer join at all times at the entity level. I have looked into writing a custom
strategy by extending RelationFieldStrategy; however, I see only addFetchInnerJoin in
JDBCFetchConfiguration class when I try to override

public void selectEagerJoin(Select sel, OpenJPAStateManager sm,
                            JDBCStore store, JDBCFetchConfiguration fetch, int eagerMode)

Can someone kindly give me a hint if this is possible or I have to extend a different class or some how set the
fetch mode to OUTER JOIN in my entity.
Henno Vermeulen | 9 Mar 09:52 2015

Java 8/Java 7 end of life


AFAIK, OpenJPA still doesn't work with Java 8. Are there any plans of fixing this soon? Perhaps OpenJPA
committers could give this some more priority?

Oracle public support for Java 7 will end after April this year, see http://www.oracle.com/technetwork/java/javase/eol-135779.html
If I understand well, this means that security issues in Oracle's Java 7 runtime will no longer be fixed so
that an application using OpenJPA on Java 7 will become more and more vulnerable over time.

The ticket for Java 8 was last updated in October 2014: https://issues.apache.org/jira/browse/OPENJPA-2386

Henno Vermeulen
Craig Taylor | 6 Mar 22:44 2015

Dynamic POJO population and child POJOs with CriterionQuery

We've built up a filter library on top of OpenJPA CriteronQuery is fairly
dynamic allowing population of a number of parameters and currently returns
the associated Entity objects correctly.

For a large majority of the web service calls however, the entity
association as well as the additional overhead retrievals are un-necessary
as we're directly populating the data into a DTO and returning it.  The
DTOs do not always map to the Entity objects being returned.

I've been able to modify the library to correctly populate a shallow (No
List<OtherClass> etc) pojo DTO by making use of an array of Selection<>

I'd like to support the ability to populate fields of child memebers. Eg,

ParentDTO  {
    List<ChildDTO> childDTO; // associated set/getChildDTO, addChildDTO

ChildDTO {
   Integer id; String firstName; String lastName; String city

I'm not sure how to define the individual elements of the ChildDTO?

Should the child be mapped in the parent as a CompundSelection<>{
Selection<Integer> idPath, Selection<String> firstName } in the parent
selection list?   Would this return me v List<Object[]> result set an array
of the corresponding child fields?

The construct() method looks interesting but I've been unable to see how I
can bend it to my will.  Is it tied to an entity object or can I map it to
individual POJO's and only for certain elements while handling child
objects selectively also?



Craig Taylor
Jörn Gersdorf | 26 Feb 08:15 2015

Commercial Support?

Hi all,

are you aware of any company offering commercial support for OpenJPA?
Google did not help me in that case.

Thank you.

Kind regards,
Hal Hildebrand | 22 Feb 22:29 2015

Lifecycle events?

So, I’m trying to use the lifecycle events on the OpenJPAEntityManagerSPI.  I’ve created a class which
implements PersistListener, UpdateListener, DeleteListener.  I’ve registered an instance of this
class as a lifecycle listener:

OpenJPAEntityManagerSPI openJpaEm = em.unwrap(OpenJPAEntityManagerSPI.class);

This does not seem to do anything at all.  I’ve got printlns in every event and I get nothing.  I have
registered the txn listener successfully, and that works great.

Is there something I’m missing here?

Any help appreciated.


padamstx | 19 Feb 02:10 2015

Problem when using <at> Generated with non-primary key column

I'm using v2.2.3 of OpenJPA with DB2 v10.5 and I've run across a problem that
occurs when an entity contains a field annotated with  <at> Generated but yet the
field is not the primary key for the entity.

Here's an approximation of my entity:

 <at> Entity
 <at> Table(name="A")
public class A {
    private int id;
    private int realId;
    private String someField;

    public A() { }

    public A(int realId) { this.realId = realId; }

     <at> Basic
     <at> GeneratedValue(strategy=GenerationType.IDENTITY)
     <at> Column(unique=true, insertable=false, updatable=false)
    public int getId() { return id; }

    public void setId(int id) { this.id = id; }

     <at> XmlElement
     <at> Id
     <at> Column(name="REAL_ID", insertable=false, updatable=false)
    public int getRealId() { return realId; }

    public void setRealId(int realId) { this.realId = realId; }

     <at> Basic
     <at> XmlElement
    public String getSomeField() { return someField; }

    public void setSomeField(String someField) { this.someField = someField;

Note that the "realId" field is not  <at> Generated because it is actually a
foreign key to another entity, hence it gets its value from that

When I try to insert an entity hierarchy containing multiple instances of
entity A (within the same transaction), I get an error like the following:

<openjpa-2.2.3-SNAPSHOT-r422266:1620420 fatal store error>
org.apache.openjpa.persistence.RollbackException: This operation failed for
some instances.  See the nested exceptions array for details.
Caused by: <openjpa-2.2.3-SNAPSHOT-r422266:1620420 fatal general error>
org.apache.openjpa.persistence.PersistenceException: This operation failed
for some instances.  See the nested exceptions array for details.
	at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1529)
	... 4 more
Caused by: <openjpa-2.2.3-SNAPSHOT-r422266:1620420 fatal user error>
org.apache.openjpa.persistence.ArgumentException: Attempt to assign id "0"
to new instance "my.package.A-0" failed; there is already an object in the
L1 cache with this id. You must delete this object (in a previous
transaction or the current one) before reusing its id.  This error can also
occur when a horizontally or vertically mapped classes uses auto-increment
application identity and does not use a hierarchy of application identity
FailedObject: my.package.A-0
	at org.apache.openjpa.kernel.ManagedCache.commitNew(ManagedCache.java:236)
	... 9 more

The odd thing is that all of the instances of entity A are actually
committed to the database and the values of the ID column are properly
generated, etc.  Notice that the exception doesn't occur during the actuall
call to EntityManager.merge(), but instead it occurs during the call to
EntityManager.commit().   This seems like OpenJPA has perhaps failed to copy
the generated values for the ID column back into their respectiive entity
instances, and then incorrectly detects that multiple entity instances are
attempting to use the same value for a column with a unique contraint on it.

Any ideas on how to work around this?

Phil Adams

View this message in context: http://openjpa.208410.n2.nabble.com/Problem-when-using-Generated-with-non-primary-key-column-tp7587738.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Leonardo K. Shikida | 16 Feb 11:38 2015

strange qbe query for tomee 1.6.0 stable (OpenJPA 2.3.0-nonfinal-1540826)


I have a query like this

    public List<E> qbe(E example) {
        OpenJPACriteriaBuilder cb = (OpenJPACriteriaBuilder)
        CriteriaQuery<E> q = cb.createQuery(clazz);
        Root<E> entity = q.from(clazz);

        q.where(cb.qbe(entity, example)); // query by example

        TypedQuery<E> tq = entityManager.createQuery(q);
        return tq.getResultList();

for entities like this

 <at> Entity
 <at> Table(name="APPUSER",uniqueConstraints= <at> UniqueConstraint(columnNames={"username"}))
public class User implements Serializable{
    private static final long serialVersionUID = 4411272750939441365L;

     <at> Id
     <at> GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

and this

 <at> Entity
public class PasswordRotationJob implements Serializable{

     <at> ManyToOne
     <at> JoinColumn(name="userId")
    private User submitter;

The QBE query seems to assume a wrong column name

Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: ORA-00904:
"T1"."USERID": invalid identifier
 {prepstmnt 1347119244 SELECT t0.id,(...), t1.id, (...), t2.id, (...)
FROM PasswordRotationJob
t0, APPUSER t1, (...) WHERE (...) AND t0.userId = t1.userId(+) (...)}
[code=904, state=42000]

Is this a bug? If so, was it addressed in TomEE 1.7.1?


Maxim Solodovnik | 27 Jan 19:53 2015

Huge String DB mapping

Hello All,

I'm trying to map Huge string to the DB:

public static final int MAX_LOG_SIZE = 1 * 1024 * 1024;
 <at> Lob
 <at> Column(name="ful_message", length = MAX_LOG_SIZE)
private String fullMessage;

Unfortunately I get column of type TEXT in my MySQL database :( (64K max)

I tried to remove  <at> Lob annotation, no luck

OpenJPA 2.3.0

Am I doing something wrong? Or it is bug in OpenJPA?

Thanks in advance!


Maxim aka solomax
zhourui | 1 Jan 05:33 2015

how to query list property with criteria query?

have entity like:
 <at> Entity
public class CompanyAttribute extends SliceJpaObject {
	 <at> PersistentCollection(fetch = FetchType.EAGER)
	private List<String> attributeList = new ArrayList<String>();

now need to select the List property 'attributeList' only in criteria query,
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<List&lt;String>> cq = cb.createQuery(List<String>.class);

CriteriaQuery<List&lt;String>> cq = cb.createQuery(List<String>.class); is
hoe to do it.


View this message in context: http://openjpa.208410.n2.nabble.com/how-to-query-list-property-with-criteria-query-tp7587532.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Trenton D. Adams | 17 Dec 01:21 2014

ClassCastException on maven enhancing

Good day,

I have a maven build.  When I run "mvn install" my unit tests run just 
fine, as does the enhancer...
[INFO] --- openjpa-maven-plugin:1.1:enhance (enhancer)  <at>  webdirectory ---
66  athome  INFO   [main] openjpa.Tool - Enhancer running on type 
190  athome  INFO   [main] openjpa.Tool - Enhancer running on type 

But, when I run "mvn install tomcat:deploy", the enhancer plugin tries 
to run again, and this...

[INFO] --- openjpa-maven-plugin:1.1:enhance (enhancer)  <at>  webdirectory ---
An error occurred while attempting to determine the version of 
[INFO] Total time: 9.535 s
[INFO] Finished at: 2014-12-16T17:18:11-07:00
[INFO] Final Memory: 13M/218M
[ERROR] Failed to execute goal 
org.codehaus.mojo:openjpa-maven-plugin:1.1:enhance (enhancer) on project 
webdirectory: Execution enhancer of goal 
org.codehaus.mojo:openjpa-maven-plugin:1.1:enhance failed: 
org.apache.xerces.parsers.XML11Configuration cannot be cast to 
org.apache.xerces.xni.parser.XMLParserConfiguration -> [Help 1]

I've been googling, and trying to debug this for awhile, and just don't 
know what it is.  Any ideas?

Maven plugin configuration below.