使用Neo4jRepository::save
(spring-data-neo4j-6.1.5
)保存下面的Dater
类时,保存挂起且永远不会返回。我认为这与我的Dater
对象有关,该对象具有由引用接口的集合定义的关系,而不是具有@Node
注解的类。这是新4J的问题吗?
//PersistentDaterMusicItem is interface. Is there a problem doing this?
@Relationship(type = "LISTENS_TO_MUSIC")
private Set<PersistentDaterMusicItem> musicItems = new HashSet<>();
//parent
@Node
public class Dater{
@Id
@GeneratedValue
//set of different implementations of PersistentDaterMusicItem
@Relationship(type = "LISTENS_TO_MUSIC")
private Set<PersistentDaterMusicItem> musicItems = new HashSet<>();
}
//inteface 1
public interface PersistentLibraryMusicItem extends PersistentDaterMusicItem{
LocalDateTime getAddedDateTime();
}
//interface 2
public interface PersistentListenedMusicItem extends PersistentDaterMusicItem{
LocalDateTime getListenedDateTime();
}
//impl 1 of PersistentDaterMusicItem
@Node
public class ListenedAppleSong extends AppleSong implements PersistentListenedMusicItem{
@Id
@GeneratedValue
private final Long id;
}
//impl 2 of PersistentDaterMusicItem
@Node
public class LibraryAppleSong extends AppleSong implements PersistentLibraryMusicItem{
@Id
@GeneratedValue
private final Long id;
}
1条答案
按热度按时间e4yzc0pl1#
事实证明,这个问题与我的想法无关。我的
ListenedAppleSong
构造函数接受的参数不是类的字段。由于Spring data希望构造函数arg作为字段存在,因此失败并返回错误:"Required property appleSong not found for class com.dapp.common.model.apple.ListenedAppleSong!"
解决方案是确保所有构造函数arg都是类中的字段。不幸的是,在执行过程中没有抛出这个错误,代码只是挂起了,所以需要一段时间才能调试。