我是JPA的新手,我创建了一个类似下面的类
/**
*
*/
package programme;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
/**
* @author anoop
*
*/
@Entity
@Table(name="course")
@Access(AccessType.FIELD)
public class programme {
@Id private int id;
private String name;
private int year;
@Transient private String comments;
//getters and setters for the fields.
}
我注意到另一个名为class的实体java类Programme.java,带有下划线,即Programme_.java。什么是这个类,为什么会这样生成。有什么方法可以阻止它的产生吗?
Programme_.java类的代码如下。
package programme;
import javax.annotation.Generated;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.StaticMetamodel;
@Generated(value="Dali", date="2014-04-27T21:32:59.433+0530")
@StaticMetamodel(programme.class)
public class programme_ {
public static volatile SingularAttribute<programme, Integer> id;
public static volatile SingularAttribute<programme, String> name;
public static volatile SingularAttribute<programme, Integer> year;
public static volatile SingularAttribute<programme, String> comments;
}
答案 0 :(得分:9)
这是你的“Canonical Metamodel”。它可以与JPA 2.x规范(第6.2节)中描述的JPA Criteria API一起使用。
阻止Eclipse生成这些类:编辑Eclipse项目属性&gt; JPA&gt; Canonical metamodel(JPA 2.0)&gt;源文件夹 - 将文件夹的值设置为“”。
答案 1 :(得分:0)
这是我对persistence.xml进行的更改prevent Java文件和使用下划线生成的类文件(导致我a problem):
diff --git a/examples/javaee7/src/main/resources/META-INF/persistence.xml b/examples/javaee7/src/main/resources/META-INF/persistence.xml
index 86d3c0c..a477432 100644
--- a/examples/javaee7/src/main/resources/META-INF/persistence.xml
+++ b/examples/javaee7/src/main/resources/META-INF/persistence.xml
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="javaee7addressbookPersistenceUnit" transaction-type="JTA">
- <exclude-unlisted-classes>false</exclude-unlisted-classes>
+ <exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
</properties>
</persistence-unit>
</persistence>
在此更改之前,正在生成以下文件: