0
JPQL:制約エラー
delete from Session where deviceId=:deviceId and username=:username
エラー:
org.hibernate.engine.jdbc.spi.SqlExceptionHelper: ERROR: update or delete on table "edge_session" violates foreign key constraint "fkh7j6o58rfwfumainodrxptobt" on table "session_contactmethods"
Sessionクラス:
@Entity
@Table(name="EDGE_SESSION")
public class Session {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@ElementCollection(targetClass=ContactMethod.class)
@Enumerated(EnumType.STRING)
private Set<ContactMethod> contactMethods;
...
}
私はcontactMethodsフィールドに特定のCascadeTypesを追加するべきか?外国のテーブルは列挙型を保持しているので、列挙型のリストを残しておきたいので、削除はうまくいかないはずです。
EDIT:作成するsession_contactmethodsテーブルは、列挙型の値ではなく、セッションとの結合キーであるかのように見えます。
# \d session_contactmethods
Table "public.session_contactmethods"
Column | Type | Modifiers
----------------+------------------------+-----------
session_id | bigint | not null
contactmethods | character varying(255) |
Foreign-key constraints:
"fkh7j6o58rfwfumainodrxptobt" FOREIGN KEY (session_id) REFERENCES edge_session(id)
# select * from session_contactmethods;
session_id | contactmethods
------------+----------------
1 | EMAIL
1 | TELEPHONE
2 | TELEPHONE
2 | EMAIL
(4 rows)
session_contactメソッドは結合テーブルのように聞こえるのですか?またはそれは文字通りContactMethod列挙型/エンティティを保持するテーブルですか? – Gimby
列挙型のリストはどのように残っていますか?それらは、セッションオブジェクトである所有者に完全に依存しています。 PSの場合、そのフィールドに "targetClass"は必要ありません。それを定義するジェネリックがあります。 –
ええ、今は、別のテーブルが関わっている可能性があると思います。とにかく、私はどのように削除を動作させるのですか?追加のカスケードアノテーションが必要なのでしょうか?それは必須ではないと思いますか? – rich