没有为实体指定标识符

没有为实体指定标识符

本文介绍了org.hibernate.AnnotationException:没有为实体指定标识符:com.ubosque.modelo.Ciudadano的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到这个错误:

  org.hibernate.AnnotationException:
没有为entity:com指定标识符。 ubosque.modelo.Ciudadano

我的课程:

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


private static final long serialVersionUID = 1L;

private int id;
private String nombre;
私人字符串apellido;
@Column(name =fecha_nac)
私人日期fechaNac;
@Column(name =lugar_nac)
private String lugarNac;
private String direccion;
私人字符串telefono;
@Column(name =estado_civil)
private String estadoCivil;
私人字符串电子邮件;
@Column(name =desc_perfil_prof)
private String descPerfilProf;

// setters& getters ...

我知道这个错误是因为没有 @Id 注释,但如果我向id变量添加 @Id ,当我部署此错误时出现:

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

这个错误只会在我删除 @Id $ b

我的项目是由 Maven 3 和依赖关系创建的通过 pom 来进行donwloaded:


  1. mysql-connector-java-5.0.8

  2. hibernate-core-4.3.9.Final


解决方案

当你有一个 @Id 存在时,你有(关于Table.indexes)的异常(你必须拥有这个异常,所以真的看不到移除它的要点)显然有一个例外,你不张贴。由于您有一个支持JPA 2.0的JPA实现并且在CLASSPATH中有一个JPA2.1 jar,反之亦然,所以它很可能找不到该注释方法(这是JPA 2.1方法IIRC)。发布原因例外将澄清哪些,并应该指出你在正确的方向


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
解决方案

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

这篇关于org.hibernate.AnnotationException:没有为实体指定标识符:com.ubosque.modelo.Ciudadano的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 04:59