AppFuse: Switching database from MySQL to PostgreSQL

Posted by Martin Homik | Posted in Java, WebApp | Posted on 04-12-2007

2

Yesterday, I tried to run my AppFuse application with PostgreSQL instead of MySQL. I ran into a CLEAN_INSERT problem which was a result of an earlier mistake. In MySQL I used a longtext type for a description field. This type corresponds to a column JPA annotation having a length attribute with the value ‘2147483647′. Obviously, this value is too high. Note, the storage required for a ‘longtext’ is L + 4 bytes, where L < 2^32. According to PostgreSQL documentation “the longest possible character string that can be stored is about 1 GB”.

In a first solution, I removed the length attribute from the JPA annotation. PostgreSQL creates per default a “character varying(255)” data type with a fixed limit of 255 characters. On the database level, it is possible to omit the limit value, the system takes then the maximum value. But, I do not know how to specify this in a JPA annotation. Anyway, now, my AppFuse runs with PostgreSQL, too.

This was quite a bit of ’small-steps’ work.

Comments (2)

Hi!
It looks like currently run into the same problem as you did.
I need to define a “text” (mediumtext/longtext) field in JPA but I’m stuck as I didn’t find a way to do this.
This is basically why I like plain SQL (for the used database) with my own SQL-Wrapper around it.
JPA seems to be a nice idea which covers most of the normal stuff but when you need to do something more “special” you run into problems.
But I have to ask is a “text” field rather some short “varchar” field (default for the Java object String) this special after all?

I have posted the question to the AppFuse group on Nabble. Follow the thread here. Here is the answer:

“I have used the JPA @Lob annotation (before @Column) in my current
project and that has resulted in a “text” type column in Postgresql.
According to the online docco for Postgres 8.0, the “text” datatype will
store strings up to “about 1GB” in length. It has suited my purposes so
far in the areas I’ve used it. “

Write a comment