【问题标题】:Spring Arangodb stores edge but fail with MappingException: Couldn't find PersistentEntity for type class java.lang.ObjectSpring Arangodb 存储边缘但因 MappingException 失败:找不到类型类 java.lang.Object 的 PersistentEntity
【发布时间】:2021-10-26 07:43:03
【问题描述】:

当 arangtoDB 边缘集合链接到不同的对象时,是否有人已经遇到过同样的问题?并且能够使用 ArangoSpring 驱动程序对此进行操作而没有任何问题?

我有这个优势

@Data
@Edge("link2User")
public class Link2User<T> {
  @Id
  private String key;

  @From
  private User user;

  @To
  private T to;

  @Getter @Setter private String data;
  ...
  public Link2User(final User user, final T to) {
    super();
    this.user = user;
    this.to = to;
  ...
}

比存储库

@Component
public interface Link2UserRepository<T> extends ArangoRepository<Link2User<T>, String> {
}

当我尝试打电话时:

@Autowired
Link2UserRepository<Item> l2uRepository;

...

Link2User<Item> link1 = new Link2User<Item>( user, Item);
v2uRepository.save(link1 );

我的链接存储在 ArangoDB 中,但出现错误:

DOP. org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.mapping.MappingException: Couldn't find PersistentEntity for type class java.lang.Object!] with root cause
org.springframework.data.mapping.MappingException: Couldn't find PersistentEntity for type class java.lang.Object!

【问题讨论】:

    标签: java spring arangodb


    【解决方案1】:

    由于类型擦除,库在运行时无法检测到泛型字段@To 的类,因此找不到相关的持久实体。

    您可以通过创建一个类来解决它:

    public class Link2UserOfItem extends Link2User<Item> {
        public Link2UserOfItem(final User user, final Item to) {
            super(user,to);
        }
    }
    

    还有:

    @Autowired
    Link2UserRepository<Item> l2uRepository;
    
    ...
    
    Link2User<Item> link1 = new Link2UserToItem( user, Item);
    l2uRepository.save(link1 );
    

    这样,Spring Data ArangoDB 将保存一个额外的类型提示字段 ("_class": "&lt;pkg&gt;.Link2UserOfItem"),并在读取时使用它来反序列化它。

    【讨论】:

    • 非常完美,谢谢...请更新调用中的拼写错误以更正新类的名称
    猜你喜欢
    • 2018-07-12
    • 2019-07-27
    • 2019-12-14
    • 1970-01-01
    • 2020-10-09
    • 1970-01-01
    • 2021-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多