Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there a class with entity name plus an underscore for JPA entity class

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;
}
like image 925
kenthewala Avatar asked Apr 27 '14 17:04

kenthewala


People also ask

How entity class is defined in JPA?

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.

How do you indicate entity in JPA?

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.

What does @entity annotation mean?

@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.

Which are the characteristics of entity class in JPA?

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.


1 Answers

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 "".

like image 147
Brian Vosburgh Avatar answered Oct 19 '22 00:10

Brian Vosburgh