JPA如何使用ORGANIZE BY ROW定义@Table

时间:2016-05-24 16:24:12

标签: jpa db2 ibm-cloud openjpa dashdb

在使用JPA定义表时,有没有办法更改指定“ORGANIZE BY ROW”参数?我正在处理的代码是

@Entity
@Table(name = "ANSWERS")
public class AnswerEntity {    
    @Id
    @Column(name = "CLASS")
    private String answerClass;

    @Lob
    @Column(name = "TEXT", unique = false, nullable = false)
    private String answerText;
}

我想添加“ORGANIZE BY ROW”等同于

CREATE TABLE ANSWERS ( CLASS VARCHAR(256), TEXT CLOB(1000000) NOT NULL ) ORGANIZE BY ROW;

1 个答案:

答案 0 :(得分:1)

看起来您可以继承org.apache.openjpa.jdbc.sql.DB2Dictionary并覆盖:

  

getCreateTableSQL

     

public String [] getCreateTableSQL(Table table)      返回一系列SQL语句来创建给定的表,      完成列。索引和约束将单独创建。

public class CutomDB2Dictionary extends DB2Dictionary{

    @Override
    public String getCreateTableSQL(Table table){
        String sql = super.getCreateTableSQL(table);

        if(table.getName().equalsIgnoreCase("ANSWERS")){
            sql += " ORGANIZE BY ROW";
        }

        return sql;
    }
}

在配置中指定自定义DB2字典:

<property name="openjpa.jdbc.DBDictionary" value="com.test.CutomDB2Dictionary "/>