How to create an entity with a table with two foreign key columns using Hibernate: No identifier specified for entity:


h

I am trying to create a table in a database that requires two foreign key columns. But I have an exception and I don't know how to fix this error:

Could you please help me?

exception:

No identifier specified for entity: com.xxx.client.db.domain.app.PhoneComp

follow my solid class

PhoneComp.class

/**
 *
 * @author joh
 */
@Entity
@Table(name = "phoneComp")
public class PhoneComp implements Serializable {

   private static final long serialVersionUID = 1L;

   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   @Basic(optional = false)
   @Column(name = "id")
   private Integer id;

   @JoinColumn(name = "cellPhoneRef", referencedColumnName = "id")
   @ManyToOne
   private Cellphone cellPhoneReference;

   @JoinColumn(name = "cellPhoneComp", referencedColumnName = "id")
   @ManyToOne
   private Cellphone cellPhoneComp;

   public PhoneComp() {}

   /**get and sets*/
}

mobile phone

/**
 *
 * @author joh
 */
@Entity
@Table(name = "cellphone")
public class Cellphone implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;

    @Column(name = "cellphoneName")
    private String cellphoneName;

    @Basic(optional = false)
    @Column(name = "isActive")
    private boolean isActive;

    @Column(name = "cellphoneBrand")
    private String cellphoneBrand;

    @Column(name = "lastModifiedDate")
    private Date lastModifiedDate;

    public Cellphone() {}

    /**get and sets **/

}
Vivek Pakmode

The PhoneComp class is missing the field annotated with @Id. Each @Entity needs an @Id - this is the primary key in the database.

If you don't want your entity to stay in a separate table, but want to be part of other entities, you can use @Embeddable instead of @Entity.

Related


hibernate: no identifier specified for entity

Patrick H I am trying to build a small project in Hibernate and use mysql docker database for demonstration. Everything worked fine until I added a new class called Flight and a corresponding FlightController. The log says: 2018-12-02 14:42:47,281 DEBUG [main]

Identifier not specified for entity in Java Hibernate

Pratic Josh I am using hibernate and I have tables mapped with beans. If I don't assign any particular column value as @id, it throws a "no identifier specified for entity" error, but it's not a primary key in my datatable. I want to add multiple records with

Identifier not specified for entity in Java Hibernate

Pratik Joshi I am using hibernate and I have the table mapped with beans. If I don't assign any particular column value as @id, it throws a "no identifier specified for entity" error, but it's not a primary key in my datatable. I want to add multiple records w

Identifier not specified for entity in Java Hibernate

Pratic Josh I am using hibernate and I have tables mapped with beans. If I don't assign any particular column value as @id, it throws a "no identifier specified for entity" error, but it's not a primary key in my datatable. I want to add multiple records with

hibernate: save entity with foreign key

Robb1 : I have a database with two entities ( Product and Feedback ) . Feedback has a single foreign key referencing a product whose primary key is an integer. Therefore, there is a one-to-one relationship between them . I want to add a new " feedback" entry t

hibernate: save entity with foreign key

Robb1 : I have a database with two entities ( Product and Feedback ) . Feedback has a single foreign key referencing a product whose primary key is an integer. Therefore, there is a one-to-one relationship between them . I want to add a new " feedback" entry t

hibernate: save entity with foreign key

Robb1 : I have a database with two entities ( Product and Feedback ) . Feedback has a single foreign key referencing a product whose primary key is an integer. Therefore, there is a one-to-one relationship between them . I want to add a new " feedback" entry t

Create fake foreign key on view using Entity Framework

Arzamar I created a view "Supplier" which shows the columns from table "T_ADDRESS". The view is declared as (I know, "*" is not feasible in a view) create View Supplier as select * from T_ADRESSEN where IsSupplier = 1 In EF, I want to use a view because it'