我是JavaEE中的新成員,很難在Intellij中使用JPA控制檯。浪費了大量的時間,同時執行JPQL查詢擺脫這種錯誤的:無法在JPA控制檯中執行JPQL查詢Intellij
jpa-ql> SELECT p FROM PersonEntity p
[2017-04-21 18:44:46] using C:\Users\admin\.IntelliJIdea2017.1\system\compiler\jpaproject4.0.82b748b3\.generated\Jpa_Console\JpaProject4.0-PU-1492789486636\META-INF\persistence.xml
[2017-04-21 18:44:48] PersonEntity is not mapped [SELECT p FROM PersonEntity p]
我在MySQL創建簡單的JavaEE持久性項目和簡單的數據庫。 我在Intellij中添加了DataSource並生成了持久化映射。 我導入了必要的庫,並擺脫了所有編譯錯誤。 我可以看到我的Database in Database工具窗口並且可以執行SQL查詢。 但由於這個令人討厭的錯誤,我無法執行JPQL查詢:PersonEntity未映射。
的persistence.xml:
<persistence-unit name="NewPersistenceUnit">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>models.PersonEntity</class>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/sample"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value=""/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
PersonEntity.java:
package models;
import javax.persistence.*;
@Entity
@Table(name = "person", schema = "sample", catalog = "")
public class PersonEntity {
private int id;
private String name;
@Id
@Column(name = "id")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Basic
@Column(name = "name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PersonEntity that = (PersonEntity) o;
if (id != that.id) return false;
if (name != null ? !name.equals(that.name) : that.name != null) return false;
return true;
}
@Override
public int hashCode() {
int result = id;
result = 31 * result + (name != null ? name.hashCode() : 0);
return result;
}
}
數據庫結構: DB structure
項目結構: Project structure
任何想法來解決這個問題?