‘ JPA ’ category archive

jpaquerytool for testing JPA queries

May 11, 08 by the programmer

Have you ever wanted to test your JPA queries without recomiling and running your application everytime you make a change. Now there is a way for doing that.

There is an open source project called “jpaquerytool“. This is basically a application that allows you to browse your JPA persistance units and execute queries and make updates to the database using JPA query language.

This is the project description taken from the website:

JQT is a query editor for Java Persistence API. The project’s main mission is to create a JPA implementation independent tool that can be used to browse pertsistence unit entities and properties, edit and run queries in a user friendly editor, browse queries results, persist and remove objects using visual editors, and provide an extensible architecture to help JPA developers add more functions. JQT parses persistence units located in its classpath, creating a entity metadata using a simple plug-in architecture to support multiple JPA implementations. Current version has support to latest versions of Hibernate Entity Manager, TopLink Essentials and OpenJPA as JPA implementations.

This is the URL of the project. Check it out

https://jpaquerytool.dev.java.net/

Can`t change database meta data with JPA

April 25, 08 by the programmer

I wanted to try to change the column name or add/drop new column using Toplink Essentials but it seems that there is no way of doing that using JPA.
TopLink Essentials can only drop and create tables, while OpenJPA by default
only adds/removes columns if the table already exist.

So you cant change the structure of your database using JPA. You have to use native queries to that or you can use some of the database tools to do that for you

Toplink essentials - no arithmetic operations in select clause

April 25, 08 by the programmer

I was testing the free ORACLE JPA implementation toplink essentials.

I downloaded the latest version “glassfish-persistence-installer-v2-b41.jar” from here http://www.oracle.com/technology/products/ias/toplink/jpa/download.html

I wanted to make a simple query that sums 2 columns in the select clause and returns the result

Someting like this for example

SELECT

p.price * p.price

FROM

Products

After trying to execute the above query I got some errors.

I tried with *, +, -, / but non of them worked, so I wrote an email to the toplink essentials community.

This is the link to my email https://glassfish.dev.java.net/servlets/ReadMsg?listName=persistence&msgNo=4062

and I got the following response:

You can either

-Do the multiplication in memory once you retrieve the result

or

-Use native sql

So this is it. You can’t do this very basic operation in a framework that should be used for complicated applications. I really can`t understand how someone can make a framework like this without the basic operations like arithmetic operations.