Kariem Hussein | 16 Jul 14:30 2015
Picon

Question regarding "constant" parameter replacement in JPQL

Hi there,

I am in the process of migrating a big (old) code base from JPA 1 with
Hibernate 3.3 to JPA 2 with OpenJPA. I've had a problem with a query that
used to work in the old version and now does not and I wanted to know
whether my reasoning is correct.

I have already reduced the problem description to the minimal and I hope I
did not lose relevant pieces of information on the way.

Given this table in Oracle

    create table PERSON (
      id char(10) not null,
      type char(3) not null,
      primary key (id)
    )

There are a lot of rows with in total three different types "WTW", "WAI",
"V" (to be honest, I don't know what they stand for). However, we have an
entity to work with this table:

     <at> Entity
    public class Person {
       String id;
       String type;
    }

The following query is used in the application from an orm.xml file:

(Continue reading)

Francesco Chicchiriccò | 16 Jul 13:45 2015
Picon

Troubles with slices

Hi all,
at Syncope we are implementing the multi-tenancy feature [1], which 
requires - at least for the way how we thought at it - to extend the 
current OpenJPA-based persistence layer with slices.

I am unfortunately experiencing some troubles, so I've assembled a 
quickstart project to show my problems [2], which replicates most of 
Syncope settings.

You can verify that, after issuing

mvn clean test

all tests (but one, which is rather irrelevant since it does not perform 
any database operation) are failing; if, instead, a single test method 
is invoked as

Konsole output mvn clean test -Dtest=RealmTest#save

everything is working as expected (this is true for every single test 
method).

The relevant part of the stacktrace is at [3]: as you can see, it seems 
that there are problems related to transaction completion.

You can find the OpenJPA setup in [3] - as you can see the application 
is Spring-managed; please note that I had to explicitly set 
"openjpa.BrokerImpl" to 
"org.apache.openjpa.slice.DistributedBrokerImpl", otherwise nothing was 
working at all.
(Continue reading)

Pawel Veselov | 15 Jul 20:34 2015
Picon

Auto-deleting referenced entities.

Hi.

Is it possible in JPA to reference entities from another, and have them
automatically delete if the reference is just removed?

I.e. if the entity is:

public class E_Campaign implements Accounted {

     <at> Id
    private long id;

     <at> OneToMany(cascade = CascadeType.ALL, mappedBy = "campaign")
    private Collection<E_VehicleAssociation> vehicles;

}

And the dependent entity is:

public class E_VehicleAssociation {

     <at> Id
    private long id;

     <at> ManyToOne
    private E_Campaign campaign;

}

Is it possible to do something like this, and have that delete the
(Continue reading)

Niraj Shah | 10 Jul 08:06 2015
Picon

Data truncation error from DBDictionary.narrow

I'm using SolidDB database using OpenJPA persistence framework. The program
has been working for a very long during (more than 3 months) and everything
has been working fine. I have checks to ensure not to enter data larger
than the DB column sizes. But suddenly I've started seeing Data truncation
issue. It is coming continuously and all inserts are failing. I'm sure that
my data has not exceeded the column width. The error does not give
information about any particular column or data type. Can anyone help in
determining root cause for this?
openjpa-2.2.2

solidDB - Version 7.0.0.7 Build 2013-08-27

Exception from logs:

Caused by: <openjpa-2.2.2-SNAPSHOT-r422266:1462076 fatal general error>
org.apache.openjpa.persistence.PersistenceException: Data truncation
at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4962)
at
org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4922)
at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:136)
at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:110)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:62)
at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:90)
at
org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:550)
at
org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:106)
(Continue reading)

Jim Talbut | 4 Jul 11:07 2015
Picon

Service returns object, but nothing is received unless toString is called!

Hi,

I have this class:
 <at> Transactional
 <at> Component
public class ProjectTransactionsImpl implements ProjectTransactions {

      <at> SuppressWarnings("constantname")
     private static final Logger logger = 
LoggerFactory.getLogger(ProjectTransactionsImpl.class);

      <at> Autowired
     private ProviderService providerService;

      <at> Override
     public Provider findProvider(String providerId) {
         Provider provider = providerService.find(providerId);
         logger.debug("Returning: {}", provider.getClass());
         return provider;
     }
}

And a unit test calling it like this:
 <at> RunWith(SpringJUnit4ClassRunner.class)
 <at> ContextConfiguration(locations = 
{"file:src/test/resources/testContext.xml"})
 <at> TransactionConfiguration(transactionManager = "transactionManager", 
defaultRollback = false)
public class MigrateProjects extends AbstractMigrationClass {

(Continue reading)

Henno Vermeulen | 2 Jul 13:36 2015
Picon

generated sql incorrectly uses inner join

I have a Department entity with two optional  <at> ManyToOne fields "faxLinkedTo" and "phoneNumberLinkedTo"
that optionally refer to another Department whose phone number of fax can be used.

I am writing a query to find out the names of departments that refer to either the fax or phone number of a given
department using the following JPQL:

SELECT d.name, d.faxLinkedTo.id, d.phoneNumberLinkedTo.id
FROM Department d
WHERE d.faxLinkedTo.id IN (:departments) OR d.faxLinkedTo IS NULL OR
               d.phoneNumberLinkedTo.id IN (:departments) OR d.phoneNumberLinkedTo IS NULL
ORDER BY d.name

As a test case I let department A link it's fax to department B by setting  A.faxLinkedTo = B, while having
A.phoneNumberLinkedTo = null.
When I run the query to find departments linking to department B, I expect it to return a row for A.

However I get an empty result because OpenJPA generates query with two inner joins and the
phoneNumberLinkedTo field is null.

I would expect the native query to use no joins at all and just do a simple select on the Department table.

Is this a bug or am I doing something wrong? Is there a way to let OpenJPA generate the correct query?

Or should I simply use two separate queries, one for faxLinkedTo and phoneNumberLinkedTo?

SELECT t0.NAME,
       t1.id,
       t2.id
FROM   dbo.crm_department t0
       INNER JOIN dbo.crm_department t1
(Continue reading)

zhourui | 1 Jul 15:29 2015
Picon

groupBy only return first row of resultSet

CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
Root<Task> root = cq.from(Task.class);
Predicate p = cb.equal(root.get(Task_.person), person);
javax.persistence.criteria.Path<String> applicationNamePath =
root.get(Task_.applicationName);
Expression<Long> countPath = cb.count(applicationNamePath);
/*here is the problem*/
cq.multiselect(applicationNamePath,
countPath).where(p).groupBy(applicationNamePath);
for (Tuple o : em.createQuery(cq).getResultList()) {
	WrapOutCountApplication wrap = new WrapOutCountApplication();
	wrap.setApplicationName(o.get(applicationNamePath));
	wrap.setCount(o.get(countPath));
	list.add(wrap);
}

expect return mulit row,but it only return the first row.
is this a bug?

--
View this message in context: http://openjpa.208410.n2.nabble.com/groupBy-only-return-first-row-of-resultSet-tp7588359.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

patrice | 1 Jul 10:05 2015
Picon

Flush throws EntityExistsException

Hello,

Flush is throwing the following exception:

.<openjpa-2.3.0-r422266:1540826 fatal store error>
org.apache.openjpa.persistence.EntityExistsException: The transaction has
been rolled back.  See the nested exceptions for details on the errors that
occurred.
FailedObject: com.xxx.d2p106.jpa.entities.V06Studies <at> 2dfec3a1
                at
org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2370)
                at
org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java)
                at
org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2105)
                at
org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1876)
                at
org.apache.openjpa.kernel.DelegatingBroker.flush(DelegatingBroker.java:1045)
                at
org.apache.openjpa.persistence.EntityManagerImpl.flush(EntityManagerImpl.java:663)
                at
com.xxx.d2p106.DatastoreUpserter.processSequence(DatastoreUpserter.java:443)

The code essentially looks like this:

                    dbTransaction = em.getTransaction();
		    dbTransaction.begin();

		    Query query = em.createNamedQuery("V06Studies.findByStudyCodeNcc");
(Continue reading)

Antoni Myłka | 29 Jun 11:59 2015

Expected an OptimistickLockException but got a SetRollbackOnlyException

Hi,

I have an issue whose cause lies somewhere between OpenJPA and Aries. Posting it here first, please
redirect me if it's the wrong place.

We use Open JPA in Karaf 3.0.2 (detailed bundle versions below). We have an DAO object, instantiated by
Blueprint with a jpa:context and a tx:transaction element. It gets the EntityManager from Aries JPA and
has a mandatory transaction on each method call.

<bean id="masterDataDao" depends-on="dataSource" class="some.package.MasterDataDaoImpl">
   <jpa:context unitname="masterDataDb" property="entityManager"/>
   <tx:transaction method="create,delete,find*,get*,update" value="Mandatory"/>
</bean>

That DAO object has CRUD methods for an entity class that uses optimistic locking. It has a long version
field annotated with  <at> Version.

Our problem appears when we get the optimistic lock error. We would expect our MasterDataDao.update
method to throw a TransactionRollbackException with an OptimisticLockException as its cause. Instead
it throws a TransactionRollbackException with a SetRollbackOnlyException as its cause (TransactionImpl.java:272).

The question is why? 

I tried debugging the issue. I put a breakpoint at
org.apache.geronimo.transaction.manager.TransactionImpl.markRollbackCause(java.lang.Throwable)
line: 539. AFAIU the problem is that that method is called *TWICE* when a transaction is processed. The
first time it is called with the "wrong" exception - SetRollbackOnlyException, the second time it's
called with the correct OptimisticLockException, but the correct exception isn't recorded in the
TransactionImpl object because the markRollbackCause method looks like this:

(Continue reading)

Mansour Al Akeel | 27 Jun 18:25 2015
Picon

Joining on unmapped Tables

In an OSGI environemnt, the JPA entities are distributed in different
OSGI Modules.
How do we query Entities in one Module, and join another entity in
different Module.

EclipleLink introduced an extention that allows using Table operator:
https://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/JPQL#TABLE

to solve this problem. Additional option is the composite Persistence Unit.

Do we have something similar to solve this problem in OpenJPA ?

How do others deal with this problem ?

Mihael Schmidt | 17 Jun 12:19 2015
Picon

OpenJPA dependency in osgi bundle with only data model classes

hi,

i have a question about openjpa. i got an osgi bundle with data models
containing jpa stuff. i have seen that the import-package line contains

org.apache.openjpa.enhance;version="[2.2,3)",org.apache.openjpa.util;version="[2.2,3)"
.

is it possible to have no package dependencies to openjpa as I am using
standard jpa stuff?

pom.xml: http://pastebin.com/wSvT03ca

Best Regards

Mihael Schmidt

--

-- 

Schulz Gebäudeservice GmbH & Co. KG
Dr.-Max-Ilgner-Straße 17
32339 Espelkamp
Persönlich haftende Gesellschafterin:
Gebäudereinigung Joachim Schulz
Verwaltungsgesellschaft mbH
Telefon: +49 5772 9100 0
Telefax: +49 5772 9100 11
Email: zentrale@...
Internet: www.sgbs.de
Geschäftsführer: Joachim und Dirk Schulz, Norbert Kosica
(Continue reading)


Gmane