Я пытаюсь использовать Select Query с JPA, но я получаю ошибку:Ошибки при выполнении оператора SELECT с использованием JPA
Это мой CountryDto.java
файл
@Entity
@Table(name = "COUNTRY")
public class CountryDto {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="COUNTRY_ID")
private int Country_Id;
@Column(name="COUNTRY")
private String Country;
// Getters & Setters go here
public CountryDto() {
// TODO Auto-generated constructor stub
}
public CountryDto(int country_Id, String country) {
// super();
Country_Id = country_Id;
Country = country;
}
}
Мой persistence.xml файл выглядит следующим образом :
<persistence-unit name="texttiledb" transaction-type="RESOURCE_LOCAL">
<class>com.textileworld.mill.Dto.CountryDto</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/texttiledb" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.ddl-generation" value="create-tables" />
</properties>
</persistence-unit>
И Это код, который я пытаюсь запустить
EntityManagerFactory emfactory = Persistence.createEntityManagerFactory("texttiledb");
EntityManager entitymanager = emfactory.createEntityManager();
entitymanager.getTransaction().begin();
Query query = entitymanager.createQuery("SELECT c FROM COUNTRY c",CountryDto.class);
List<CountryDto> rol= (List<CountryDto>) query.getResultList();
for (CountryDto con : rol){
System.out.println(con);
}
entitymanager.getTransaction().commit();
entitymanager.close();
emfactory.close();
Но я не знаю, почему он показывает ошибку, что он абстрактный тип схемы «СТРАНА» неизвестен.
Здесь ошибка, что я получаю:
Exception Description: Problem compiling [SELECT c FROM COUNTRY c]
[14, 21] The abstract schema type 'COUNTRY' is unknown.
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1605)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1625)
at com.textileworld.mill.Dao.CountryDao.main(CountryDao.java:24)
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Problem compiling [SELECT c FROM COUNTRY c].
[14, 21] The abstract schema type 'COUNTRY' is unknown.
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:155)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:347)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:278)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:163)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:142)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:116)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:102)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:86)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1603)