我有一个带有postgres数据库的春季启动应用程序
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.0.0.jre7</version>
</dependency>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
我做了一个简单的测试来创建一个用户,从Db加载它,更改其中一个属性并再次保存
但它不起作用
这是我的UserInterface
public interface UserService extends CrudRepository<User, String> {
public final static String NORMAL_USER = "ROLE_user";
public User findByEmail(String email);
public User findByVerificationToken(String token);
}
和我的junit测试
@Test
public void activateUser(){
User user = new User();
user.setRegistrationDate(new Date());
user.setEnabled(false);
user.setEmail("junit@test.com");
user.setPassword("12");
userService.save(user);
User dbUser = userService.findByEmail("junit@test.com");
assertFalse(user.isEnabled());
dbUser.setEnabled(true);
userService.save(dbUser); <--- here it dies
dbUser = null;
User activatedUser = userService.findByEmail("junit@test.com");
assertTrue(activatedUser.isEnabled());
}
如前所述,测试会创建用户,findByEmail也能正常工作 但是当我更改持久化对象并再次调用save方法时,我得到以下例外
2017-05-03 18:49:20.242错误3852 --- [主要] o.h.engine.jdbc.spi.SqlExceptionHelper:ERROR:运算符没有 存在:字符变化= bigint提示:没有运算符匹配 给定名称和参数类型。您可能需要添加显式类型 管型。职位:581 2017-05-03 18:49:20.244 INFO 3852 --- [
main] o.h.e.internal.DefaultLoadEventListener:HHH000327:错误 执行load命令:org.hibernate.exception.SQLGrammarException: 无法提取ResultSet 2017-05-03 18:49:20.320 INFO 3852 --- [
Thread-5] o.s.w.c.s.GenericWebApplicationContext:Closing org.springframework.web.context.support.GenericWebApplicationContext@3cc1435c: 启动日期[Wed May 03 18:49:12 COT 2017];上下文层次结构的根
我无法理解错误,因为我没有比较任何事情......
更新 - 添加用户类
@Entity
@Table(name = "users")
public class User implements UserDetails {
private static final long serialVersionUID = -4009074751138066325L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long userId;
@Column(name = "first_name")
private String firstName;
@Column(name = "last_name")
private String lastName;
@Column(name = "auth_provider")
private String authProvider;
@Email
@NotNull
@Column(name = "email")
private String email;
@Column(name = "dob")
private String dob;
@Column(name = "doc_type")
private String documentType;
non args constructor and getters/setters
}