jpaリポジトリを作成しようとしていますが、外部キーのプライマリキーに問題があります。抽象基底クラス(MessageDestination
)で指定されていますが、特殊なMessageDestination
クラスのリポジトリ(例えばMessageDestinationRoom
)のリポジトリからは見えません。名 'messageDestinationRoomDAO' を持つBeanを作成エラー:〜JpaRepositoryの "IdClass not defined"を継承した@OneToOne @Idについて
[...]ネストされた例外はorg.springframework.beans.factory.BeanCreationExceptionがあるinitメソッドの呼び出しに失敗しました。ネストされた例外は、java.lang.IllegalArgumentExceptionがある:このクラス[クラスcom.chat.message.entity.MessageDestinationRoom]私は、私のように
MessageDestination
に注釈を付けることができたことを見た問題を解決するためにIdClass
@Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Message implements Serializable {
@Id @GeneratedValue(strategy = GenerationType.TABLE)
private Long id;
@OneToOne(targetEntity = MessageDestination.class,
cascade=CascadeType.ALL, mappedBy="msg")
@NotNull
private MessageDestination dest;
//...
}
@Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class MessageDestination implements Serializable {
@Id @OneToOne(cascade=CascadeType.ALL)
private Message msg;
}
@Entity
public class MessageDestinationRoom extends MessageDestination {
@OneToOne @NotNull
private Room destRoom;
//...
}
public interface MessageDestinationRoomDAO
extends JpaRepository<MessageDestinationRoom, Message> {
public Set<MessageDestinationRoom> findMessageDestinationRoomByDestRoom
(Room dest);
}
を定義していません。 @MappedSuperclass
が格納されますが、これはMessage
に格納するためには@Entity
である必要があります。悲しいことに、それは不可能です。
org.hibernate.AnnotationException:エンティティは@Entityと@MappedSuperclass
の両方で注釈を付けることはできません
任意のアイデア?ありがとう...
:
が、このなります。実際には 'SINGLE_TABLE'戦略ではなく' TABLE_PER_CLASS'を使用します。あなたの提案は次の例外を引き起こします:_org.hibernate.AnnotationException:未知のmappedBy:com.test.Message.dest、未知のプロパティ:com.test.MessageDestination.msg_。ありがとうございます。 :) –