使用Spring Data neo4j创建空间索引时出错 [英] Error in creating spatial Index using Spring Data neo4j
问题描述
我正在研究Neo4j Spring Data项目,并希望在节点上执行一些与空间相关的操作.
I'm working on Neo4j Spring Data project and wants to perform some spatial related operation on nodes.
实体类
@NodeEntity
public class User {
@GraphId
Long id;
private String fname;
private String lname;
private String uname;
private String pwd;
private Double latitude, longitude;
@Indexed(indexType = IndexType.POINT, indexName = "geom")
private String wkt;
public void setLocation(Double lon, Double lat) {
this.wkt = String.format("POINT( %.2f %.2f )", lon, lat);
}
@RelatedTo(type = "KNOWS", direction = Direction.OUTGOING)
public Set<User> knows;
//getter and setter methods
控制器
@RequestMapping(path = URI_SAVE, method = RequestMethod.POST)
public String handleUriSave(@ModelAttribute(value = "insuser") User user) {
System.out.println("save method called");
System.out.println("User : " + user);
try {
User retrivedUser = userService.findUser(user);
if (retrivedUser != null) {
if (retrivedUser.getUname().equals(user.getUname())) {
throw new Exception("User Already Exist !!");
}
}
user.setLocation(user.getLongitude(), user.getLatitude());
userService.create(user);
UserServiceImpl
@Service
public class UserServiceImpl implements IUserService {
@Autowired
private UserEntityRepository userrepository;
@Override
public User create(User user) {
return userrepository.save(user);
}
UserEntityRepository
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.neo4j.repository.SpatialRepository;
import org.springframework.stereotype.Repository;
import com.ga.data.entity.User;
@Repository
public interface UserEntityRepository extends GraphRepository<User>, SpatialRepository<User> {
User findByUname(String uname);
}
在保存用户时,它会给出异常,
At the time of saving the user it gives exception,
EXCEPTION
java.lang.RuntimeException: Erroraddingelement0wktPOINT(85.4225.02)toindexgeomstatus500{
"message": "No such property, 'wkt'.",
"exception": "NotFoundException",
"fullname": "org.neo4j.graphdb.NotFoundException",
"stackTrace": [
"org.neo4j.kernel.impl.core.NodeProxy.getProperty(NodeProxy.java:469)",
"org.n
xNodeWrapper.addNode(LegacyIndexNodeWrapper.java:52)",
"org.neo4j.kernel.impl.api.StateHandlingStatementOperations.nodeAddToLegacyIndex(StateHandlingStatementOperations.java:1420)",
"org.neo4j.kernel.impl.api.Ope
LegacyIndexProxy.java:390)",
"org.neo4j.server.rest.web.DatabaseActions.addToNodeIndex(DatabaseActions.java:699)",
"org.neo4j.server.rest.web.RestfulGraphDatabase.addToNodeIndex(RestfulGraphDatabase.java:1059)",
"
java:745)"
],
"errors": [
{
"code": "Neo.DatabaseError.General.UnknownFailure",
"message": "No such property, 'wkt'.",
"stackTrace": "org.neo4j.graphdb.NotFoundException: No such property, 'wkt'.\r\n\tat org.neo4j.kernel
x.add(LayerNodeIndex.java:41)\r\n\tat org.neo4j.gis.spatial.indexprovider.LegacyIndexNodeWrapper.addNode(LegacyIndexNodeWrapper.java:52)\r\n\tat org.neo4j.kernel.impl.api.StateHandlingStatementOperations.nodeAd
egacyIndexProxy.internalAdd(LegacyIndexProxy.java:536)\r\n\tat org.neo4j.kernel.impl.coreapi.LegacyIndexProxy.add(LegacyIndexProxy.java:390)\r\n\tat org.neo4j.server.rest.web.DatabaseActions.addToNodeIndex(Data
reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.lang.reflect.Method.invoke(Method.java:606)\r\n\tat com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(
her.dispatch(ResourceJavaMethodDispatcher.java:75)\r\n\tat org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)\r\n\tat com.sun.jersey.server.impl
ri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)\r\n\tat com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)\r\n\tat com.sun.jersey.server.impl.appl
9)\r\n\tat com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)\r\n\tat com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)\r\n\tat
ervletHolder.handle(ServletHolder.java:800)\r\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)\r\n\tat org.neo4j.server.rest.web.CollectUserAgentFilter.doFilter(Coll
a:221)\r\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125)\r\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)\r\n\tat org.eclipse.jetty.serv
ndle(HandlerList.java:52)\r\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)\r\n\tat org.eclipse.jetty.server.Server.handle(Server.java:497)\r\n\tat org.eclipse.jetty.server.
a:620)\r\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:540)\r\n\tat java.lang.Thread.run(Thread.java:745)\r\n"
}
]
}
我是neo4j DB的新手.我已经阅读了一些文章,并通过neo4j中的REST API创建了索引,但是使用spring数据创建neo4j会出现这种类型的异常. 我正在使用neo4j-community-2.3.1-windows版本和spring-data-neo4j 3.4.0 RELEASE版本.
I am new to neo4j DB. I have read some articles and created index via REST API in neo4j but creating with spring data neo4j gives this type of exception. I'm using neo4j-community-2.3.1-windows version and spring-data-neo4j 3.4.0 RELEASE version.
任何建议.
推荐答案
您正在使用哪个版本的spring-data-neo4j?您是否正在使用spring-data-neo4j-rest?还是嵌入在服务器中?
Which version of spring-data-neo4j are you using? Are you using spring-data-neo4j-rest? Or embedded within the server?
这是以前存在的用户吗?
Was this a user which existed before?
在例外情况下,似乎缺少一些堆栈跟踪.
In the exception there seems to be a bit of stacktrace missing.
您可以通过单元测试来拒绝它吗?
Can you repoduce it with a unit test?
这篇关于使用Spring Data neo4j创建空间索引时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!