I have Quiz entity which is mapped to a table called Option with @ElementCollection.
so the logic is if the user want to delete the quiz, all the options related to it would be deleted.
I have create this named query
@NamedQuery(name = "deleteOptionsOfQuiz",
query = "DELETE FROM quiz_option q WHERE q.quizID = :quizId")
})
but I'm getting this error
Caused by: org.hibernate.HibernateException: Errors in named queries:
deleteOptionsOfQuiz failed because of: org.hibernate.hql.internal.ast.QuerySyntaxException: quiz_option is not mapped [DELETE FROM quiz_option q WHERE q.quizID = :quizId]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:360)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:471)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build
here are the tables
QUIZ
public class Quiz{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "quizID")
private long id;
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "quiz_option",
joinColumns = @JoinColumn(name = "quizID"))
@Column(name = "option")
private Set<String> options= new HashSet<>();
//...
}
Option
<changeSet author="***" id="***">
<createTable tableName="quiz_option">
<column name="quizID" type="BIGINT">
<constraints foreignKeyName="quiz" references="quiz(quizID)" nullable="false"/>
</column>
<column name="option" type="NVARCHAR(50)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>