Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8930659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:56:18+00:00 2026-06-15T08:56:18+00:00

Background: I’m writing a little desktop application with connection to existing SQL Server DB.

  • 0

Background: I’m writing a little desktop application with connection to existing SQL Server DB.

I’m quite familiar with writing SQL queries but this time I want to give JPA a shot. I have my entities mapped and everything is fine, but I’m little worried about perfomance.

I made some profiling and the result is that the JPA code is not really slower than mapping by hands. But there is a still one problem that is bugging me.

I’ve recorded the queries with SQL Server Profiler and Eclipse link is constantly calling exec sp_prepexec and exec sp_unprepare with the same query but diffent parameters.

I’ve rewriten the code to use parameters in query, but still no luck.

The class code is:

In constructor I create EntityManagerFactory and EntityManager

    emf = Persistence.createEntityManagerFactory("ZapytaniaOKonta_1.0");
    em = emf.createEntityManager();
    query=prepareQuery();

In prepareQuery I prepare the query using criteria builder and parameters

    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Uczestnik> criteria = builder.createQuery(Uczestnik.class);
    Root<Uczestnik> uczestnikRoot = criteria.from(Uczestnik.class);
    criteria.select(uczestnikRoot);
    ParameterExpression<Boolean> peselFilterParameter = builder.parameter(Boolean.class, "peselFilterParameter");
    ParameterExpression<String> peselParameter = builder.parameter(String.class, "peselParameter");
    Predicate peselPredicate = orBuilder(builder, uczestnikRoot, peselParameter, peselFilterParameter, Uczestnik_.pesel);

    ParameterExpression<Boolean> nipFilterParameter = builder.parameter(Boolean.class, "nipFilterParameter");
    ParameterExpression<String> nipParameter = builder.parameter(String.class, "nipParameter");
    Predicate nipPredicate = orBuilderNip(builder, uczestnikRoot, nipParameter, nipFilterParameter, Uczestnik_.nip);

    ParameterExpression<Boolean> regonFilterParameter = builder.parameter(Boolean.class, "regonFilterParameter");
    ParameterExpression<String> regonParameter = builder.parameter(String.class, "regonParameter");
    Predicate regonPredicate = orBuilder(builder, uczestnikRoot, regonParameter, regonFilterParameter, Uczestnik_.regon);

    criteria.where(builder.and(peselPredicate, nipPredicate, regonPredicate));
    uczestnikPeselRegonNipQuery = em.createQuery(criteria);
    return uczestnikPeselRegonNipQuery;

when using the query I set all the parameters and call

    query.getResultList();

So my question is how can I make EclipseLink or other JPA2 provider use prepared statements?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:56:19+00:00Added an answer on June 15, 2026 at 8:56 am

    EclipseLink does not use a statement cache by default. To enable one use,

    “eclipselink.jdbc.cache-statements”=”true”

    This can only be used with EclipseLink’s connection pooling. When using a JavaEE DataSource, you need to enable statement caching in your JavaEE server’s DataSource config.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I have an installation of VisualSVN on a server. under this, I have
BACKGROUND I'm writing a little game using Java, slick2d and other frameworks. Slick2d does
Background: This is really a general best-practices question, but some background about the specific
Background: I'm trying to setup a VPN server on android phone. For, this I
Background I am working on modernizing a pre-existing PHP-driven website. This website started out
Background: We're building an application that allows our customers to supply data in a
Background The main application where I work is based heavily on the MUMPS-esque Caché
Background: I have an application with an alternate entry point. It listenes for SMS
Background: I have a little video playing app with a UI inspired by the
Background: Some time ago, I built a system for recording and categorizing application crashes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.