Off-topic? How to extract database statements from JPA?

Started by Gus Spierover 3 years ago3 messagesgeneral
Jump to latest
#1Gus Spier
gus.spier@gmail.com

I apologize if this is off-topic, but I've become exceedingly frustrated
and need help.

The assignment is to evaluate SQL code for an application that has been
built with Java Springer Persistence API and, if appropriate, offer
suggestions to improve database performance.

The problem is that I am not a Java guy. I can usually read code and
determine what it is trying to do. But here, I am at a loss. Where does the
JPA hide the SQL code? I do not really expect a definitive, explicit
answer, but if anybody could point me to documentation or a working aid
that lays out where the JPA stores the DDL and DML, I would be truly
grateful.

Thanks in advance.

Gus

#2Erik Wienhold
ewie@ewie.name
In reply to: Gus Spier (#1)
Re: Off-topic? How to extract database statements from JPA?

On 31/10/2022 11:50 CET Gus Spier <gus.spier@gmail.com> wrote:

I apologize if this is off-topic, but I've become exceedingly frustrated and
need help.

The assignment is to evaluate SQL code for an application that has been built
with Java Springer Persistence API and, if appropriate, offer suggestions to
improve database performance.

The problem is that I am not a Java guy. I can usually read code and determine
what it is trying to do. But here, I am at a loss. Where does the JPA hide the
SQL code? I do not really expect a definitive, explicit answer, but if anybody
could point me to documentation or a working aid that lays out where the JPA
stores the DDL and DML, I would be truly grateful.

My JPA knowledge is a bit rusty and I only worked with Hibernate before.
Which JPA implementation do you use?

In case of Hibernate you can enable logging:

org.hibernate.SQL => DEBUG
org.hibernate.type.descriptor.sql => TRACE

If you also use Spring you can try the following config instead:

spring.jpa.show-sql = true
spring.jpa.properties.hibernate.format_sql = true

--
Erik

#3negora
public@negora.com
In reply to: Gus Spier (#1)
Re: Off-topic? How to extract database statements from JPA?

Hi Gus:

JPA (Jakarta Persistence API; previously known as Java Persistence API)
is "just" the specification. There are several implementations of this.
The reference implementation is EclipseLink, but there are others widely
used such as Hibernate or OpenJPA. You should ask which one is being
used in your company.

The SQL code is generated on the fly, so there is no place where it's
stored. However, there are ways to view what SQL is generated in real
time. For example, with Hibernate, you can change the level of the
"org.hibernate.SQL" logger to "DEBUG", and view what happens behind the
scenes.

You could also enable the logging in the PostgreSQL server-side and see
what's happening.

Best regards.

Show quoted text

On 31/10/2022 11:50, Gus Spier wrote:

I apologize if this is off-topic, but I've become exceedingly
frustrated and need help.

The assignment is to evaluate SQL code for an application that has
been built with Java Springer Persistence API and, if appropriate,
offer suggestions to improve database performance.

The problem is that I am not a Java guy. I can usually read code and
determine what it is trying to do. But here, I am at a loss. Where
does the JPA hide the SQL code? I do not really expect a definitive,
explicit answer, but if anybody could point me to documentation or a
working aid that lays out where the JPA stores the DDL and DML, I
would be truly grateful.

Thanks in advance.

Gus