1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DbUnitでPostgreSQLのinet型を使う

Posted at

PostgreSQLのinet型が定義されたテーブルにDbUnitを使用してデータをセットアップしようとした際に、対処した方法を載せます。

環境

OSS Version
Java 7
postgresql 9.5
mybatis 3.4.2
dbunit 2.5.3

対処前に発生するエラー

org.dbunit.dataset.NoSuchColumnException: users.ADDR - (Non-uppercase input column: addr)
usersというテーブルのADDRカラムがinet型です。

対処方法

PostgresqlDataTypeFactoryクラスを使う
使い方は以下の通り。
DatabaseConnectionに対してPostgresql独自の型を提供するクラスを追加してあげます。
getDBConnection()の実装は「Spring + Mybatis + DbUnit を使ってみた」を参照ください。

sample.java
DatabaseConnection connection = getDBConnection();
connection
    .getConfig()
    .setProperty(
        DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
        new PostgresqlDataTypeFactory()
     );
     
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?