我有一個普通的JPA實體與生成的ID-屬性:JPA並含有
@Entity(name = "AUTO_COMPLETION")
public class AutoCompletion extends AbstractEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "aip_seq")
@SequenceGenerator(name = "aip_seq", sequenceName = "aip_seq", allocationSize = 1)
@Column(name = "ID")
private Long id;
...
}
我創建JPA實體:
AutoCompletion c2a1 = new AutoCompletion();
c2a1.setClient(c2);
c2a1.setText("c2a1");
c2a1.setType(AutoCompletionType.PERSON);
autoCompletionService.create(c1a1);
創建如下實現的:
@Override
public T create(final T t) {
this.em.persist(t);
return t;
}
現在,實體與ID屬性集一起被寫入數據庫。我想通過一個函數再次檢索:
List<AutoCompletion> completions = autoCompletionService.getAutoCompletions()
我想我可以打電話給
completions.contains(c2a1)
但它總是返回false ...我不明白爲什麼。它不應該返回真實?
您是否實現了equals方法? –
沒有它的默認值。但我認爲entitymanger會照顧 – matthias
您使用哪個JPA提供商?你能看到哪個是方法返回的List實現? –