Archive for April, 2008

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.

JAVA integer division

April 25, 08 by the programmer

I was trying some divisions in Java when suddenly I noticed that the result is not the one that I expected

So I took my calculator to check and I noticed that I am not seeing things

So this is what I did

I took 2 numbers and tried to divide them to check the results

Here is what the results were

int i = 7;

int j = 2;

int k = i / j; // gives 3

double res1 = (double) i / ( double) j; // gives 3.5

double res2 = (double) ( i / j ); // gives 3.0

double res3 = ((double) i ) / j; // gives 3.5, j is promoted to double automatically.



So if you take 2 integer numbers and divide them then the result will be an integer number

So be carefull what you divide in JAVA :)