我有 A B 两个表,结构完成一样
Apojo
@Table("a")
public class APojo {
@Name
protected String id; // int(11) NOT NULL
@Column("name")
protected String names = "名字";// char(10) NOT NULL
@Column("age")
protected int age;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getNames() {
return names;
}
public void setNames(String names) {
this.names = names;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}; // int(11) NULL
}
Bpojo
@Table("b")
public class BPojo extends APojo {
}
业务逻辑是 假设 A中不存在某个记录, 去B表找,并且插入 A 表
@At("/feinto")
public void feinto() {
APojo apojo = dao.fetch(APojo.class, Cnd.where("id", "=", "479db588067e43828be9cd3f045b4d6f"));
if (apojo == null) {
System.out.println("null-----------------------");
apojo = dao.fetch(BPojo.class, Cnd.where("id", "=", "479db588067e43828be9cd3f045b4d6f"));
System.out.println(apojo.getId());
System.out.println(apojo.getAge());
System.out.println(apojo.getNames());
}
dao.insert(apojo);
}
蛋疼的是,,,出现 id 异常,
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '479db588067e43828be9cd3f045b4d6f' for key 'PRIMARY'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1041)