Hibernate的会话工厂,没有识别标识符

时间:2015-11-25 13:49:40

标签: java mysql eclipse hibernate mapping

我收到一个非常奇怪的hibernate错误。我已经映射了我的MySQL数据库中的所有实体,感谢hibernate代码生成,我已经建立了所有的关系,一切似乎都有效,但现在我收到了这个错误

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$4.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$1.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配置时出现错误,而如果我只刷新它,它可以工作但不允许我看到Session Factory,因为这个错误。

1 个答案:

答案 0 :(得分:1)

确保您拥有正确的导入:

import javax.persistence.Id;

而不是

import org.springframework.data.annotation.Id;

希望这有效