2

Is there a way to change specify a "ORGANIZE BY ROW" argument when defining a table with JPA? The code I'm working on is

@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;
}

I'd like to add an "ORGANIZE BY ROW" equivalent to

CREATE TABLE ANSWERS ( CLASS VARCHAR(256), TEXT CLOB(1000000) NOT NULL ) ORGANIZE BY ROW;
Sari
  • 21
  • 1
  • 1
    Even if it's possible (I don't know if it is), you probably shouldn't mix physical implementation details of a database table with the abstraction that JPA provides. – mustaccio May 24 '16 at 19:58

1 Answers1

1

Looks like you could subclass the org.apache.openjpa.jdbc.sql.DB2Dictionary and override:

getCreateTableSQL

public String[] getCreateTableSQL(Table table) Return a series of SQL statements to create the given table, complete with columns. Indexes and constraints will be created separately.

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;
    }
}

Specify your custom DB2 dictionary in the config:

<property name="openjpa.jdbc.DBDictionary" value="com.test.CutomDB2Dictionary "/>
Alan Hay
  • 22,665
  • 4
  • 56
  • 110
  • Have you tried using this in bluemix with javaee7.0. I am not able to get this working for my JPA with DashDB. DashDB uses organize by column as default and JPA does not work well with it. So i am tryign to set create queries with organize by row. I was very hopeful that your solution works for dashdb but could not get it working. Could you please help. – Sacky San Jun 27 '16 at 06:47
  • I suggest raising this as a query with Bluemix support. This should work "out of the box", so there could be an underlying product issue that needs to be ironed out. – Nick Maynard Oct 07 '16 at 10:35
  • In which maven package is DB2Dictionary class ? – Mindaugas Jaraminas Nov 03 '16 at 14:27
  • http://www.findjar.com/index.x;jsessionid=DE9148FDD4543D85D59ECCA07A48F9BC?query=.DB2Dictionary – Alan Hay Nov 03 '16 at 14:47
  • No. It is for OpenJpa. – Alan Hay Nov 07 '16 at 09:06