を返す私のエンティティの抜粋である(それはまた、ハッシュコードを持っており、作成した等しくjavaのHibernateはいつもここ
ここ@Entity
@Table(name = "media_tspec_external_registry")
public class Registry implements Serializable {
public Registry() {
//for hibernate :D
}
public Registry(String show, String protocol, String externalEndpoint, String userURI, String version) {
super();
this.show = show;
this.protocol = protocol;
this.externalEndpoint = externalEndpoint;
this.userURI = userURI;
this.version = version;
}
@Id
@Column(name = "show", nullable = false)
private String show;
@Id
@Column(name = "protocol", nullable = false)
private String protocol;
@Column(name = "external_endpoint", nullable = true)
private String externalEndpoint;
によって生成されるデフォルトのものであるにしようとしている私の方法であり、これらのキーの値
Registry reg = new Registry("invalid", "idvalue", null, null, null);
Registry reg2 = null;
try {
reg2 = (Registry) session.load(Registry.class, reg);
} catch (HibernateException e) {
throw new UserException("A registry entry does not exist for this show: " + show + " and protocol: " + protocol);
}
に基づいて、存在しないエンティティをロードし、それは例外とREG2は今nullに設定されているすべてのフィールドを持つレジストリオブジェクトに設定されているスローすることはありません。
私はまた、負荷が既存のエンティティを読み込まないことにも気付きました。私は(非既存のオブジェクトにnullを返す有効なオブジェクトをロードする)期待どおりに動作する代わりに取得
reg2 = (Registry) session.get(Registry.class, reg);
を使用する場合
は、しかし、任意の説明をいただければ幸いです。
ありがとう
奇妙な。レジストリは同時にエンティティと複合キーの両方ですか? –
@PiotrKochański[hibnate docs](http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#entity-mapping-identifier)セクション2.2.3.2.2に基づいています。私は、エンティティ自身がシリアライズ可能な識別子(idclassまたは組み込みIDに似ている)であることを意味するようにしました –
質問への回答をご覧くださいhttp://stackoverflow.com/q/608947/971040 それはあなたを右に向けるかもしれません方法。 – viktor