Hibernate sessionfactory 不识别标识符

Hibernate's session factory and no recognizing identifier

我收到一个非常奇怪的休眠错误。由于休眠代码生成,我已经映射了我的 MySQL 数据库中的所有实体,我已经设置了所有关系并且一切似乎都正常,但现在我收到了这个错误

org.hibernate.AnnotationException: No identifier specified for entity: com.YouDroop.Data.Entities.Showcase
at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:243)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:775)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3845)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3799)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1373)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.tools.hibernate.runtime.common.Util.invokeMethod(Util.java:43)
at org.jboss.tools.hibernate.runtime.common.AbstractConfigurationFacade.buildMappings(AbstractConfigurationFacade.java:160)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:272)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:108)
at org.hibernate.console.ConsoleConfiguration.buildMappings(ConsoleConfiguration.java:270)
at org.hibernate.eclipse.console.workbench.ConsoleConfigurationWorkbenchAdapter.getChildren(ConsoleConfigurationWorkbenchAdapter.java:44)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.getChildren(BasicWorkbenchAdapter.java:98)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:104)
at org.eclipse.ui.progress.DeferredTreeContentManager.run(DeferredTreeContentManager.java:232)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

实体Showcase是这个

@Entity
@Table(name = "showcase", schema = "youdroopnorelationships")
public class Showcase implements Serializable {

private static final long serialVersionUID = 1L;

private int code;
private Function function;
private String description;
private int capacity;
private int currentNumberOfProducts;

public Showcase() {
}

public Showcase(int code, Function function, int capacity, int currentNumberOfProducts) {
    this.code = code;
    this.function = function;
    this.capacity = capacity;
    this.currentNumberOfProducts = currentNumberOfProducts;
}

public Showcase(int code, Function function, String description, int capacity, int currentNumberOfProducts) {
    this.code = code;
    this.function = function;
    this.description = description;
    this.capacity = capacity;
    this.currentNumberOfProducts = currentNumberOfProducts;
}

@Id
//@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "Code", unique = true, nullable = false)
public int getCode() {
    return this.code;
}

public void setCode(int code) {
    this.code = code;
}

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "Function_Name", nullable = false)
public Function getFunction() {
    return this.function;
}

public void setFunction(Function function) {
    this.function = function;
}

@Column(name = "Description", length = 100)
public String getDescription() {
    return this.description;
}

public void setDescription(String description) {
    this.description = description;
}

@Column(name = "Capacity", nullable = false)
public int getCapacity() {
    return this.capacity;
}

public void setCapacity(int capacity) {
    this.capacity = capacity;
}

@Column(name = "CurrentNumberOfProducts", nullable = false)
public int getCurrentNumberOfProducts() {
    return this.currentNumberOfProducts;
}

public void setCurrentNumberOfProducts(int currentNumberOfProducts) {
    this.currentNumberOfProducts = currentNumberOfProducts;
}

}

如您所见,我已将所有注释写在正确的位置,甚至是 @Id 注释,che .hbm 文件也反映了它。 当我重建 Hibernate 配置时出现错误,而如果我只刷新它,它可以工作但不允许我看到会话工厂,因为这个错误。

确保你有正确的导入:

import javax.persistence.Id;

而不是

import org.springframework.data.annotation.Id;

希望这有效