Monday, July 4, 2011

Oracle Toplink + PostgreSQL = nightmare

Banyak masalah yang muncul ketika memakai Oracle Toplink sebagai persistence provider dan PostgreSQL sebagai databasenya, antara lain:
1. Tidak mau menjalankan sequence. Solusi:

package edu.mat.client;

import oracle.toplink.essentials.platform.database.PostgreSQLPlatform;
import oracle.toplink.essentials.queryframework.ValueReadQuery;
import oracle.toplink.essentials.sessions.DatabaseSession;

public class PostgreSQLPlatformSupportingSequences extends PostgreSQLPlatform {

/**
*
*/
private static final long serialVersionUID = -2637524409846222203L;

public boolean shouldNativeSequenceAcquireValueAfterInsert() {
return false;
}

public void platformSpecificSequencingInitialization(DatabaseSession session) {
}

public ValueReadQuery buildSelectQueryForNativeSequence(String seqName,
Integer size) {
ValueReadQuery selectQuery = new ValueReadQuery();
selectQuery.setSQLString("select nextval(\'" + seqName + "\')");
return selectQuery;
}

}

Terus tambahkan di persistence.xml <property name="toplink.target-database" value="edu.mat.client.PostgreSQLPlatformSupportingSequences"/>

2. Muncul error Problem with sequence setup increment does not match its pre-allocation size. Solusi: Ubah current-value di sequence menjadi 100, dan increment-value menjadi genap semisal dua.

3. Data byte dengan annotation @Lob seperti

@Column(name = "PICTURE", table = "USER_PICTURES")
@Lob
@Basic(fetch = FetchType.LAZY)
public final byte[] getPicture() {
return picture;
}

harus didefinisikan dengan tipe oid di PostgreSQL

0 comments:

 

©2009 Stay the Same | by TNB