Datanucleus - 无法从数字单元格中获取文本值

Datanucleus - Cannot get a text value from a numeric cell

我想使用 DataNucleus 读取和写入 .xls 文件。我在 Apache POI 上发现了很多这个问题,但如果没有必要,我不想直接使用 Apache POI,而不是 DataNucleus。

所以,我有一个测试class:

@Entity
@Table(name = "JUSTSTRING")
public class JustStringEntity {

    @Id
    @Column
    private Integer id;

    @Column
    private String name;
}

还有一些方法,将其写入 .xls,然后从那里读取。

public void exportSomeToXls(){
    JustStringEntity e1 = new JustStringEntity(); e1.setId(1); e1.setName("Mr. Salieri");
    JustStringEntity e2 = new JustStringEntity(); e2.setId(2); e2.setName("Thomas Angelo");

    EntityTransaction tx = xlsManager.getTransaction();
    tx.begin();
    xlsManager.persist(e1);
    xlsManager.persist(e2);
    tx.commit();
}

public void getSomeFromXls(){
    try {
        List<JustStringEntity> entities = xlsManager.createQuery("SELECT j from JustStringEntity j", JustStringEntity.class).getResultList();

        System.out.println("SIZE: " + entities.size());

        for (JustStringEntity j : entities) {
            System.out.println(j.getId());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

成功将数据写入.xls文件。但是当我尝试阅读它时,出现以下错误:

java.lang.IllegalStateException: Cannot get a text value from a numeric cell
    at org.apache.poi.hssf.usermodel.HSSFCell.typeMismatch(HSSFCell.java:637)
    at org.apache.poi.hssf.usermodel.HSSFCell.getRichStringCellValue(HSSFCell.java:714)
    ....

如果 JustStringEntity 只包含 String 属性,它工作正常。但如果它包含任何数字数据,它将失败。

有什么简单的方法可以解决这个问题(不直接使用 Apache POI)吗?

尝试将 Long/Integer 更改为 long/int(原始)。

虽然我仍然希望它能与原始包装器一起使用,但也许 was/is 在特定情况下存在一些错误?