Spring Data Rest(SDR)错误:PersistentEntity不能为null

时间:2015-04-26 10:57:12

标签: spring-data-rest

我正在努力通过SDR公开我的Spring数据存储库。当我导航到我的休息网址(http://localhost:8080/trxes)时,出现错误: {"原因":null,"消息":" PersistentEntity必须不能为空!"}

仔细检查spring数据源后,我看到getRepositoryFactoryInfoFor()方法返回空的存储库信息,即

mysqld: Can't find file: './mysql/plugin.frm' (errno: 13 - Permission denied)
2015-04-26 12:48:32 1663 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2015-04-26 12:48:32 1663 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-04-26 12:48:32 1663 [Note] InnoDB: The InnoDB memory heap is disabled
2015-04-26 12:48:32 1663 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-04-26 12:48:32 1663 [Note] InnoDB: Memory barrier is not used
2015-04-26 12:48:32 1663 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-04-26 12:48:32 1663 [Note] InnoDB: Using CPU crc32 instructions
2015-04-26 12:48:32 1663 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-04-26 12:48:32 1663 [Note] InnoDB: Completed initialization of buffer pool
2015-04-26 12:48:32 1663 [Note] InnoDB: Highest supported file format is Barracuda.
2015-04-26 12:48:32 1663 [Note] InnoDB: Log scan progressed past the checkpoint lsn 49463
2015-04-26 12:48:32 1663 [Note] InnoDB: Database was not shutdown normally!
2015-04-26 12:48:32 1663 [Note] InnoDB: Starting crash recovery.
2015-04-26 12:48:32 1663 [Note] InnoDB: Reading tablespace information from the .ibd files...
2015-04-26 12:48:32 7fff72404300  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: Error: could not open single-table tablespace file ./test/cities.ibd
InnoDB: We do not continue the crash recovery, because the table may become
InnoDB: corrupt if we cannot apply the log records in the InnoDB log to it.
InnoDB: To fix the problem and start mysqld:
InnoDB: 1) If there is a permission problem in the file and mysqld cannot
InnoDB: open the file, you should modify the permissions.
InnoDB: 2) If the table is not needed, or you can restore it from a backup,
InnoDB: then you can remove the .ibd file, and InnoDB will do a normal
InnoDB: crash recovery and ignore that table.
InnoDB: 3) If the file system or the disk is broken, and you cannot remove
InnoDB: the .ibd file, you can set innodb_force_recovery > 0 in my.cnf
InnoDB: and force InnoDB to continue crash recovery here.

我的问题的可能原因是我的持久实体继承自单个基类,并且我使用单表策略如下:

数据库中有一个TRX表,带有匹配的Trx类。 VariableIncome,VariableExpense,FixedIncome和FixedExpense都继承自Trx并持久存储到TRX表。

private RepositoryFactoryInformation<Object, Serializable> getRepositoryFactoryInfoFor(Class<?> domainClass) {

    Assert.notNull(domainClass, "Domain class must not be null!");

    RepositoryFactoryInformation<Object, Serializable> repositoryInfo = repositoryFactoryInfos.get(ClassUtils
            .getUserClass(domainClass));
    return repositoryInfo == null ? EMPTY_REPOSITORY_FACTORY_INFO : repositoryInfo;
}

所有子类看起来类似于下面显示的VariableIncome:

    @Entity
    @Table(name = "TRX")
    @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
    @DiscriminatorColumn(name = "TRX_TYPE", discriminatorType = DiscriminatorType.STRING)
    abstract public class Trx extends AbstractPersistable<Long> {

我的存储库设置是(此类没有注释):

    @Entity
    @DiscriminatorValue("VARIABLE_INCOME")
    public class VariableIncome extends Trx {

我使用以下方式运行所描述的设置:

public interface TrxRepository extends CrudRepository<Trx, Long> {

我想我正在寻找的是,是否有一种方法可以告诉SDR(当它试图推断我的持久类是什么时)所有子类应该映射回Trx?

1 个答案:

答案 0 :(得分:1)

这是&#34; REST&#34;对于&#34; DATA&#34;侧。

您需要使用Jackson注释来输入类型信息。

@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include = As.PROPERTY, property = "@class")

您可以找到更多here,因为根据您的使用案例和偏好设置了几种方法。