Search code examples
hibernatejpahibernate-annotations

org.hibernate.AnnotationException: No identifier specified for entity: com.ubosque.modelo.Ciudadano


I get this error:

org.hibernate.AnnotationException:
No identifier specified for entity: com.ubosque.modelo.Ciudadano

my class:

@Entity
@Table(name="ciudadano")
public class Ciudadano implements java.io.Serializable {


private static final long serialVersionUID = 1L;

private int id;
private String nombre;
private String apellido;
@Column(name="fecha_nac")
private Date fechaNac;
@Column(name="lugar_nac")
private String lugarNac;
private String direccion;
private String telefono;
@Column(name="estado_civil")
private String estadoCivil;
private String email;
@Column(name="desc_perfil_prof")
private String descPerfilProf;

// setters & getters ...

I know this error is because there is no @Id annotation, but if I add @Id to the id variable, when I deploy this error appears:

javax.servlet.ServletException:
javax.persistence.Table.indexes()[Ljavax/persistence/Index;

and this error ONLY disappears when I remove the @Id annotation, so any suggestions will be appreciated.

my project is made with Maven 3 and the dependencies donwloaded through pom are:

  1. mysql-connector-java-5.0.8
  2. hibernate-core-4.3.9.Final

Solution

  • The exception that you have (about Table.indexes) when you have an @Id present (which you must have, so really don't see the point in removing it) clearly has a cause exception that you don't post. More than likely it cannot find that annotation method (which is a JPA 2.1 method IIRC) since you have either a JPA implementation supporting JPA 2.0 and have a JPA2.1 jar in the CLASSPATH or vice-versa. Posting the cause exception would clarify which, and should have pointed you in the right direction