Spring boot findByPropertyAndReleation未提供所需的实体
我正在导入历史足球或足球,如果您来自美国,请使用spring-boot-starter-data-Neo4j依赖项的spring-boot应用程序2.1.6.RELEASE和本地运行的独立3.5.6 Neo4j数据库服务器将数据导入Neo4j数据库 但由于某些原因,通过简单属性和附加的引用实体搜索实体并不起作用,尽管数据库中存在这种关系 这是模型中让我头疼的部分:Spring boot findByPropertyAndReleation未提供所需的实体,spring-boot,kotlin,spring-data,spring-data-neo4j,Spring Boot,Kotlin,Spring Data,Spring Data Neo4j,我正在导入历史足球或足球,如果您来自美国,请使用spring-boot-starter-data-Neo4j依赖项的spring-boot应用程序2.1.6.RELEASE和本地运行的独立3.5.6 Neo4j数据库服务器将数据导入Neo4j数据库 但由于某些原因,通过简单属性和附加的引用实体搜索实体并不起作用,尽管数据库中存在这种关系 这是模型中让我头疼的部分: @NodeEntity(label = "Season") open class Season( @Id @Gene
@NodeEntity(label = "Season")
open class Season(
@Id
@GeneratedValue
var id: Long? = null,
@Index(unique = true)
var name: String,
var seasonNumber: Long,
@Relationship(type = "IN_LEAGUE", direction = Relationship.OUTGOING)
var league: League?,
var start: LocalDate,
var end: LocalDate
)
@NodeEntity(label = "League")
open class League(
@Id
@GeneratedValue
var id: Long? = null,
@Index(unique = true)
var name: String,
@Relationship(type = "BELONGS_TO", direction = Relationship.OUTGOING)
var country: Country?
)
我忽略了乡村课,因为我很确定这不是问题的一部分
为了允许多次运行导入,我想检查数据库中是否已经存在相应的实体,并且只导入较新的实体。因此,我在存储库中添加了以下方法:
open class SeasonRepository : CrudRepository<Season, Long> {
fun findBySeasonNumberAndLeague(number: Long, league: League): Season?
}
但是,当我在neo4j包上启用更精细的日志记录时,我在日志文件中看到以下输出:
MATCH (n:`Season`) WHERE n.`seasonNumber` = { `seasonNumber_0` } AND n.`league` = { `league_1` } WITH n RETURN n,[ [ (n)-[r_i1:`IN_LEAGUE`]->(l1:`League`) | [ r_i1, l1 ] ] ], ID(n) with params {league_1={id=30228, name=1. Bundesliga, country={id=29773, name=Deutschland}}, seasonNumber_0=1}
因此,出于某种原因,spring数据似乎认为league属性是一个简单/原始属性,而不是完全相关,需要通过id n.league={league_1}来解决
我只是通过传递联盟id,并使用@query注释提供一个自定义查询,才让它起作用,但我实际上认为,它可以在spring-data-neo4j开箱即用的情况下工作
谢谢你的帮助。如果您需要更多详细信息,请告诉我。Spring Data Neo4j目前不支持对象作为参数。如果这是一个合适的解决方案,可以查询相关实体/节点的属性,例如FindByseanSonnumberandLeagueName。您可以尝试一种只使用findByLeague的方法,看看是否有效?@SimonMartinelli我添加了fun FindByleAgueAgue:League:List方法,但它给了我一个空列表。运行查询匹配s:Season-[:IN_LEAGUE]->l:LEAGUE,其中idl=31214返回s.name给我56个结果我从调试器复制了联盟的id 31214。在日志中,似乎spring data试图将league解析为简单属性:查询与原始问题中完全相同,只是遗漏了季节编号部分:
MATCH (n:`Season`) WHERE n.`seasonNumber` = { `seasonNumber_0` } AND n.`league` = { `league_1` } WITH n RETURN n,[ [ (n)-[r_i1:`IN_LEAGUE`]->(l1:`League`) | [ r_i1, l1 ] ] ], ID(n) with params {league_1={id=30228, name=1. Bundesliga, country={id=29773, name=Deutschland}}, seasonNumber_0=1}