I am new to JPA, I have created a class like the following
/**
*
*/
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.
}
I noted that there is another class with name as my entity java class Programme.java with an underscore i.e. Programme_.java. What is this class and why is this generated. Is there any way that I can stop its generation?
the code for the Programme_.java class is as following.
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;
}
To transform this class into an entity add @Entity and @Id annotation in it. @Entity - This is a marker annotation which indicates that this class is an entity. This annotation must be placed on the class name. @Id - This annotation is placed on a specific field that holds the persistent identifying properties.
The JPA specification requires the @Entity annotation. It identifies a class as an entity class. You can use the name attribute of the @Entity annotation to define the name of the entity. It has to be unique for the persistence unit, and you use it to reference the entity in your JPQL queries.
@Entity annotation defines that a class can be mapped to a table. And that is it, it is just a marker, like for example Serializable interface.
Entity Properties Persistability - An object is called persistent if it is stored in the database and can be accessed anytime. Persistent Identity - In Java, each entity is unique and represents as an object identity.
This is your "Canonical Metamodel". It can be used with the JPA Criteria API, as described by the JPA 2.x spec (Section 6.2).
To stop Eclipse from generating these classes: edit your Eclipse project properties > JPA > Canonical metamodel (JPA 2.0) > Source folder - set the folder's value to "".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With