Search code examples
javadatasetdbunit

Creating DBUnit dataset with specified records


I'm using DBUnit to create dataset that will contain only records with proper IDs.

Set ids = new HashSet();
ids.add(new BigDecimal(34552));
TablesDependencyHelper.getDataset(connection, "MYTABLE", ids);

But I get dataset that contains all the records from this table (+record from some dependent tables).

Also I'm confused about composite primary keys. For example, I have ID1 and ID2 columns as primary key - how to create dataset in this case (with specified records only)?


Solution

  • After some time I realize that the only way to do it with DBUnit is:

    QueryDataSet queryDataSet = new QueryDataSet(connection);
    queryDataSet.addTable("MYTABLE", "SELECT * FROM MYTABLE WHERE ID=34552");