我有一个非常简单的类User,它应该创建包含用户信息和登录详细信息的用户对象。
package com.example.domain;
import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship;
import java.util.HashSet;
import java.util.Set;
@NodeEntity
public class User {
public User() {}
@GraphId
private Long id;
private String username;
private String password;
private String name;
private String email;
private String Role;
@Relationship(type="BELONGS_TO", direction = Relationship.INCOMING)
Set<Item> items = new HashSet<>();
public User(String name, String username, String password, String email) {
this.name = name;
this.username = username;
this.password = password;
this.email = email;
}
// Getters and setters below for private fields...
}
创建对象的控制器如下所示:
@RequestMapping(value = "/register",method = RequestMethod.POST)
public String register(Model model,
@ModelAttribute(value="name") String name,
@ModelAttribute(value="username") String username,
@ModelAttribute(value="email") String email,
@ModelAttribute(value="password") String password,
@ModelAttribute(value="confirmPassword") String confirmPassword) {
if(!password.equals(confirmPassword)) {
model.addAttribute("error", true);
return "register";
}
User userEntity=new User(name,username,password,email);
userManagementService.save(userEntity); //<------The object is created but the error occures during persistance
return "login";
}
我的用户管理服务如下:
public interface UserManagementService {
List<User> listAll();
User save(User user);
User findUser(String username);
}
什么是User类,而不是persistable类的实例。持久化类的特征是什么?如何使用户成为可持续的类?
答案 0 :(得分:1)
您是否在某处配置了OGM?在Java配置中还是在ogm.properties文件中?您需要指定驱动程序类型并告诉SessionFactory在哪里查找您的域对象。
OGM配置参考:https://neo4j.com/docs/ogm-manual/2.1/reference/#reference:configuration SessionFactory配置参考:https://neo4j.com/docs/ogm-manual/2.1/reference/#reference:connecting:session-factory