直截了当,问题是将对象操作员保存到MySQL DB中.在保存之前,我尝试从此表中进行选择并且它可以正常工作,因此是与db的连接.
这是我的Operator对象:
@Entity
public class Operator{
@Id
@GeneratedValue
private Long id;
private String username;
private String password;
private Integer active;
//Getters and setters...
}
Run Code Online (Sandbox Code Playgroud)
为了保存我使用JPA EntityManager的persist方法.
这是一些日志:
Hibernate: insert into Operator (active, password, username, id) values (?, ?, ?, ?)
com.mysql.jdbc.JDBC4PreparedStatement@15724a0: insert into Operator (active,password, username, id) values (0, 'pass', 'user', ** NOT SPECIFIED **)
Run Code Online (Sandbox Code Playgroud)
我看到它的方式,问题是配置自动增量但我无法弄清楚在哪里.
试过我在这里看到的一些技巧: Hibernate不尊重MySQL auto_increment主键字段但是没有任何有用的
如果需要任何其他配置文件,我将提供它们.
DDL:
CREATE TABLE `operator` (
`id` INT(10) NOT NULL AUTO_INCREMENT,
`first_name` VARCHAR(40) NOT NULL, …Run Code Online (Sandbox Code Playgroud) 我怀疑名称属性是否存在于两者中
@Entity和@Table
例如,我可以为name属性设置相同的值
@Entity(name = "someThing")
@Table(name = "someThing")
Run Code Online (Sandbox Code Playgroud)
同一个班级我也可以有不同的名字
@Entity(name = "someThing")
@Table(name = "otherThing")
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我这两者之间有什么区别以及为什么我们两者都有相同的属性?
我认为这可能是重复的:模式验证:缺少表[hibernate_sequences],但我无法弄清楚。
因此,在我的application.properties文件中,我有此选项:spring.jpa.hibernate.ddl-auto=validate并且收到此错误:
Schema-validation: missing table [game]
为什么我收到这个?
这是我的Game课和User课:
游戏:
@Entity
public class Game {
@Id
@Column(name = "GAME_NUMBER")
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long gameNumber;
private int playerScore;
private int NPCScore;
private Date datetime;
@ManyToOne
@JoinColumn(name="USER_ID")
private User user;
public Game() {}
public Game(int playerScore, int nPCScore, Date datetime) {
super();
this.playerScore = playerScore;
this.NPCScore = nPCScore;
this.datetime = datetime;
}
public User getUser() {
return user;
}
} + getters …Run Code Online (Sandbox Code Playgroud)