kkharlin | 31 Aug 12:55 2015

SchemaTool events on columns modification

Hello, 

We use OpenJPA 2.2.2 and want to implement some sort of automigration
mechanism in our product. The goal is to find out the columns that were
added (fields were added in entities). 

As I understood OpenJPA use SchemaTool's "addColumn" method to add new
column to the DB during EM initialization. Is there any easy way to catch
such cases (kind of events or smth) without forking and modifying this tool? 

Now we have one solution: reflect on DB and get schema as XML files before
and after EM initialization and make a diff to find the columns that were
added. But we have a big DB schema and these two reflections take almost 2
minutes on solution start :( 

Any suggestions are appreciated. 

Thank you.

--
View this message in context: http://openjpa.208410.n2.nabble.com/SchemaTool-events-on-columns-modification-tp7588470.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Pawel Veselov | 25 Aug 09:49 2015
Picon

strange coalesce?

Hi.

In OpenJPA 2.2.2, with this CB query:

CriteriaBuilder cb = ...getCriteriaBuilder();
CriteriaQuery<Long> q = cb.createQuery(Long.class);
Root<E_UpdateCurrent> root = q.from(E_UpdateCurrent.class);
Expression<Boolean> installed =
        cb.coalesce(root.get(E_UpdateTarget_.installed), cb.literal(false));
q.where(cb.isFalse(installed));
q.select(cb.count(root));
entityManager.createQuery(q).getSingleResult();

Generates the following SQL:

891973  Snap  TRACE  [ajp-nio-9181-exec-107] openjpa.jdbc.SQL - <t
802018654, conn 982796314> executing prepstmnt 408515169 SELECT
COUNT(t0.id) FROM current_updates t0 WHERE (
COALESCE(t0.installed,true) = ?) [params=?]

I assume the '?' will be 'false'

Do I understand correctly this looks like a bug? E_UpdateTarget.installed
is a boolean field.

Thanks!

  Pawel.
Christian Schneider | 20 Aug 11:24 2015
Picon

Incorrect import range for javax.transaction makes openjpa incompatible to jta 1.2

We recently updated karaf to use jta 1.2 as it provides a standard 
 <at> Transactional annotation for usage in user code.

The problem is that openjpa does not work with jta 1.2. As far as I can 
tell the issue is only an incorrect import range.
I opened an issue for this but got no response till now:
https://issues.apache.org/jira/browse/OPENJPA-2607

There is also a much older issue to create a karaf feature file during 
the openjpa build:
https://issues.apache.org/jira/browse/OPENJPA-2465

As we just released karaf 4.0.1 it will take about a month till the next 
bugfix release. We need new openjpa releases with at least the first 
issue solved. Until then openjpa will not work correctly in karaf with 
aries transaction 1.1.x.

I can do the work of creating the patches or github pull requests if you 
prefer.

Christian

--

-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com

(Continue reading)

Christian Schneider | 20 Aug 11:24 2015
Picon

Incorrect import range for javax.transaction makes openjpa incompatible to jta 2.1

We recently updated karaf to use jta 1.2 as it provides a standard 
 <at> Transactional annotation for usage in user code.

The problem is that openjpa does not work with jta 1.2. As far as I can 
tell the issue is only an incorrect import range.
I opened an issue for this but got no response till now:
https://issues.apache.org/jira/browse/OPENJPA-2607

There is also a much older issue to create a karaf feature file during 
the openjpa build:
https://issues.apache.org/jira/browse/OPENJPA-2465

As we just released karaf 4.0.1 it will take about a month till the next 
bugfix release. We need new openjpa releases with at least the first 
issue solved. Until then openjpa will not work correctly in karaf with 
aries transaction 1.1.x.

I can do the work of creating the patches or github pull requests if you 
prefer.

Christian

--

-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com

(Continue reading)

sim085 | 16 Aug 20:06 2015
Picon

TypedQuery on ElementCollection

Hello,

I have an object User which has a Map<String, String> variable named
"properties". This variable is declared as follows:

[code]
   <at> ElementCollection(fetch = FetchType.EAGER)
   <at> JoinTable(name="USER_PROPERTIES", 
      joinColumns= <at> JoinColumn(name="USER_ID"))
   <at> MapKeyColumn(name="Name")
   <at> Column(name="Value")
  private Map<String, String> properties = new HashMap<>();
[/code]

I would like to now load all Users which have some given properties (ex:
where user has property "HAIR" equals "BROWN" and "EYES" equals "WHITE").

With normal SQL the query would look something like this:

[code]
SELECT u.ID FROM USERS u, USER_PROPERTIES p1, USER_PROPERTIES p2
WHERE u.ID = p1.USER_ID AND u.ID = p2.USER_ID
AND (p1.NAME = 'HAIR' AND p1.VALUE = 'BROWS')
AND (p2.NAME = 'EYES' AND p2.VALUE = 'WHITE');
[/code]

However I do not know how to write this in JPQL

Is it possible to write the above SQL with JPQL?

(Continue reading)

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)


Gmane