Jump to content

Recommended Posts

Posted (edited)

Boas, estou a tentar importar tabelas e os seus respectivos dados para uma base de dados em memoria a partir dum ficheiro XML que foi criado automaticamente usando o DBUnit. Tem aqui duas classes de mapeamente que estou a usar.

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

Esta aqui o meu 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>

E este é o codigo que estou a usar para importar para a base de dados.

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

O problema é que estou a ter este erro:

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

O que me esta a dar cabo da cabeça é que no ficheiro XML tenho uma tabela com o nome de SPREADSHEET_CELL. A tabela WORKBOOK_SPREADSHEET é a ultima tabela do ficheiro XML.

Alguem sabe o que se passa?

Edited by Baderous
geshi

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.