Я хочу удалить человека по его id
, но выдает ошибку:
Исключение в потоке "main" java .lang.IllegalArgumentException: Неизвестная сущность: org.hibernate. query.internal.QueryImpl
Методы поиска сущности в работе базы данных:
public class MySQLPersonDAO implements PersonDAO {
@Override
public void deleteById(int id) {
EntityManager em = FACTORY.createEntityManager();
EntityTransaction transaction = em.getTransaction();
transaction.begin();
TypedQuery query = em.createQuery("SELECT p FROM Person p WHERE p.id = :id", Person.class);
query.setParameter("id", id);
em.remove(query); // hier mistake
transaction.commit();
em.close();
}
Person
@Entity
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "person_id")
private int id;
private String name;
private String password;
//getters,setters,constructor
постоянство Нужно ли явно указывать все сущности?
<persistence-unit name="myjpa">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class> com.evghenii.domain.Person</class>
<properties>
<property name="hibernate.connection.driver_class" value="com.mysql.cj.jdbc.Driver"/>
<property name="hibernate.connection.password" value="root"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/board_jpa?serverTimezone=Europe/Berlin"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL8Dialect"/>
<!--<property name="hibernate.hbm2ddl.auto" value="create"/>-->
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
maven
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.11.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.19</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.4.12.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.17.Final</version>
</dependency>
</dependencies>
</project>