0
当观察一些日志条目时,我观察到一种行为,我不明白。 我重新创建了这个场景。JPA2实体中的奇怪行为
实体:
@Entity
public class SimpleEntity implements Serializable {
private static final long serialVersionUID = 2777681889998131084L;
@Id
@GeneratedValue
private Long id;
@Version
private Long version;
@Column(length = 20, nullable = false, unique = true, updatable = false)
@NotNull
private String username;
@Column(length = 60)
private String email;
// Constructors
// getters/setters
// @Override
// toString : generated by eclipse, modified to include super.toString
// hashCode, equals : generated by eclipse, based on 'username'
}
测试用例
@Test
public void testUpdate() {
SimpleEntity simple;
SimpleEntity simple2;
try {
simple = bean.create(new SimpleEntity("user",
"[email protected]")); // em.persist
simple.setEmail("[email protected]");
simple2 = bean.update(simple); // em.merge
System.out.println(simple);
System.out.println(simple2);
} catch (EJBException e) {
System.out.println(e.getMessage());
}
}
它打印下对应上面的System.out.println线线
[email protected] SimpleEntity [id=1, version=1, username=user, [email protected]]
[email protected] SimpleEntity [id=1, version=2, username=user, [email protected]]
我感到奇怪的是地址对于两个实体都是相同的(SimpleEntity @ 36ebea),但如果我查看数据,则不一样。 '版本'是不同的。 ( & )
如何相同的实例(如地址是相同的),显示出不同的数据?有一些代理正在玩吗?怎么样?
哦!谢谢@zagyi – 2013-02-21 04:25:20