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