我正在研究Neo4j Spring Data项目,并希望在节点上执行一些与空间相关的操作。
实体类
@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);
}
在保存用户时,它会提供异常,
异常
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版本。
任何建议请。
答案 0 :(得分:1)
您使用的是哪个版本的spring-data-neo4j?你在使用spring-data-neo4j-rest吗?还是嵌入在服务器中?
这是以前存在的用户吗?
在异常中似乎缺少一些堆栈跟踪。
你可以用单元测试来重新制作吗?