简体   繁体   中英

Error in creating table in in-memory database using DBUnit

I'm trying to import the data and tables from a XML file to an in-memory database, which XML file I create automatically using DBUnit. Here are two of the classes I'm mapping: WorkbookMapping:

@Entity(name="Workbook")
public class WorkbookMapping implements Serializable {
@Id
@GeneratedValue
private int id;

@OneToMany(cascade = CascadeType.ALL )
List<SpreadSheetMapping> list = new ArrayList<SpreadSheetMapping>();

public WorkbookMapping() {
}

public WorkbookMapping(Workbook workbook) {
    for (int i = 0; i < workbook.getSpreadsheetCount(); i++) {
        list.add(new SpreadSheetMapping(workbook.getSpreadsheet(i)));
    }

}
}

SpreadSheetMapping:

@Entity(name="Spreadsheet")
public class SpreadSheetMapping implements Serializable {
@Id
@GeneratedValue
private long id;

@OneToMany(cascade = CascadeType.ALL)
List<CellMapping> list;

public SpreadSheetMapping() {
}

public SpreadSheetMapping(Spreadsheet sp) {
    list = new ArrayList<CellMapping>();
    for (int r = 0; r < sp.getRowCount(); r++) {
        for (int i = 0; i < sp.getColumnCount(); i++) {
             list.add(new CellMapping(sp.getCell(i, r)));
        }
    }
}
}

Here is my hibernate.cfg.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="hibernate.cache.use_query_cache">false</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:mem:DBMemoria</property>
<property name="connection.username"/>
<property name="connection.password"/>
<property name="connection.pool_size">1</property>
<mapping class="csheets.io.WorkbookMapping"/>
<mapping class="csheets.io.SpreadSheetMapping"/>
<mapping class="csheets.io.CellMapping"/>
</session-factory>
</hibernate-configuration>

And this is the code I'm using to import all the data to the database:

Connection jdbcConnection;
jdbcConnection = DriverManager.getConnection("jdbc:hsqldb:mem:DBMemoria", "", "");
IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
IDataSet dataSet = new XmlDataSet(stream);
DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);

And I'm getting this error:

org.dbunit.dataset.NoSuchTableException: WORKBOOK_SPREADSHEET   
at org.dbunit.database.DatabaseDataSet.getTableMetaData(DatabaseDataSet.java:288)
at org.dbunit.operation.DeleteAllOperation.execute(DeleteAllOperation.java:109)

Any help?

Your entites are not for table which you defined in import file. You should add

@Entity
@Table(name = "WORKBOOK_SPREADSHEET")

on proper entity.

@Adam, I think we need to see the XML DataSet. As @Aleksandra mentions the classes you have do not create a WORKBOOK_SPREADSHEET table. The entities have to be mapped to tables in you XmlDataSet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM