openjpa

Combining JPA and JDBC actions in one transaction

寵の児 提交于 2019-12-04 03:31:33
问题 So, I have an application with some legacy JDBC calls in it that I need to update with some additional JPA actions. I need to be able to make both JDBC calls and JPA calls as part of the same DB transaction. I'm using OpenJPA 2.1.1 and Postgres 9.1, if it matters. The following code appears to work correctly - I've run some basic tests, and both the JDBC and JPA statements execute; an error in either one results in the pair of statements not happening (e.g. they're part of the same DB

How do I configure OpenJPA SQL logging?

∥☆過路亽.° 提交于 2019-12-04 02:26:21
What is the OpenJPA configuration to view SQL query executed in a database? I would like to view the query with all parameters executed in log or console instead of viewing the JPQL query <property name="openjpa.Log" value="SQL=Trace" /> Enables logging of all SQL statements, minus parameter values. <property name="openjpa.ConnectionFactoryProperties" value="PrintParameters=true" /> Enables logging of SQL parameters. Logging documentation If you're using log4j, you can setup your log4j.properties file as follows, which will display both the native SQL query and any parameters: log4j.rootLogger

setFirstResult and setMaxResult doesn't work well with Order By

无人久伴 提交于 2019-12-03 21:48:15
What could cause the CriteriaQuery orderBy method stop working? Here are the implementations: OpenJPAEntityManager kem = OpenJPAPersistence.cast(entityManager()); kem.getFetchPlan().clearFetchGroups(); kem.getFetchPlan().addFetchGroup("order_search"); CriteriaBuilder builder = kem.getCriteriaBuilder(); CriteriaQuery<Order> query = builder.createQuery(Order.class); Root<Order> order = query.from(Order.class); query.select(order); Predicate main_condition = buildWhereClause(builder, query, order, target_states, orderDate_from, orderDate_to, dueDate_from, dueDate_to, username); query.where(main

Database sharding and JPA

给你一囗甜甜゛ 提交于 2019-12-03 11:19:33
I am working on a Java application that requires horizontal partitioning of data in different PostgreSQL servers. I would like to use a JPA framework and Spring for transaction management. The most popular frameworks for sharding data with JPA seem to be Hibernate Shards , which appears to be no longer in development, and OpenJPA Slice , which does not support virtual shards (one of my requirements). Are there any other options that I'm missing, or a way to get around the OpenJPA limitation? Thanks in advance for your input! You can have a look at Sharding-JDBC , it is a JDBC driver for shard

jpa lazy fetch entities over multiple levels with criteria api

蓝咒 提交于 2019-12-03 06:56:47
I am using JPA2 with it's Criteria API to select my entities from the database. The implementation is OpenJPA on WebSphere Application Server. All my entities are modeled with Fetchtype=Lazy. I select an entity with some criteria from the database and want to load all nested data from sub-tables at once. If I have a datamodel where table A is joined oneToMany to table B, I can use a Fetch-clause in my criteria query: CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<A> cq = cb.createQuery(A.class); Root<A> root = cq.from(A.class); Fetch<A,B> fetch = root.fetch(A_

can I perform a query inside of JPA entity to get back a single column

荒凉一梦 提交于 2019-12-02 10:21:51
I have a dumb question. It would be great if this could be done, but I am not holding my breath. I need a single column from a table linked to my JPA entity to be a collection in said JPA entity. Is there any way, that I can just get back that column alone that is related to that entity, instead of having to get back an entire table (which could be very costly?) Can I perform a query inside that JPA entity that will be performed and loaded eagerly into a collection? I am trying to avoid having to make several calls to the database by just executing a couple of queries. What are your thoughts

OpenJPA - Nested OneToMany relationships merge issue

心已入冬 提交于 2019-12-02 07:56:03
问题 Posting this here as I wasn't seeing much interest here: http://www.java-forums.org/jpa/96175-openjpa-one-many-within-one-many-merge-problems.html Trying to figure out if this is a problem with OpenJPA or something I may be doing wrong... I'm facing a problem when trying to use OpenJPA to update an Entity that contains a One to Many relationship to another Entity, that has a One to Many relationship to another. Here's a quick example of what I'm talking about: @Entity @Table(name = "school")

OpenJPA - Nested OneToMany relationships merge issue

天涯浪子 提交于 2019-12-02 07:48:10
Posting this here as I wasn't seeing much interest here: http://www.java-forums.org/jpa/96175-openjpa-one-many-within-one-many-merge-problems.html Trying to figure out if this is a problem with OpenJPA or something I may be doing wrong... I'm facing a problem when trying to use OpenJPA to update an Entity that contains a One to Many relationship to another Entity, that has a One to Many relationship to another. Here's a quick example of what I'm talking about: @Entity @Table(name = "school") public class School { @Column(name = "id") protected Long id; @Column(name = "name") protected String

WebSphere (8.5.5) does not logging OpenJPA

不打扰是莪最后的温柔 提交于 2019-12-02 07:48:02
问题 I'm interested in logging SQL statements. I've tried two approaches, with log4j2 and writing to file, both in vain. I've added following lines to persistence.xml <property name="openjpa.Log" value="SQL=TRACE" /> <property name="openjpa.Log" value="File=openjpa_ra.log" /> <property name="openjpa.ConnectionFactoryProperties" value="PrintParameters=true" /> and I'm expecting it to write to the file, but nothing happened. On the other hand, when I specify <property name="openjpa.Log" value="log4j

WebSphere (8.5.5) does not logging OpenJPA

倖福魔咒の 提交于 2019-12-02 03:26:37
I'm interested in logging SQL statements. I've tried two approaches, with log4j2 and writing to file, both in vain. I've added following lines to persistence.xml <property name="openjpa.Log" value="SQL=TRACE" /> <property name="openjpa.Log" value="File=openjpa_ra.log" /> <property name="openjpa.ConnectionFactoryProperties" value="PrintParameters=true" /> and I'm expecting it to write to the file, but nothing happened. On the other hand, when I specify <property name="openjpa.Log" value="log4j" /> instead of file line, nothing is changes in my log4j2 files, despite having configured appender.