Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate Eclipse未知实体(使用javax.persistence.Entity)_Java_Eclipse_Hibernate_Jpa - Fatal编程技术网

Hibernate Eclipse未知实体(使用javax.persistence.Entity)

Hibernate Eclipse未知实体(使用javax.persistence.Entity),java,eclipse,hibernate,jpa,Java,Eclipse,Hibernate,Jpa,为了解决eclipse中未知实体的问题,我整天都在尝试和搜索。 我使用单独的.java和hbm.xml文件 我的实体类是Account.java // default package package com.mywebservice.domain; // Generated Sep 9, 2013 3:55:42 PM by Hibernate Tools 3.4.0.CR1 import java.util.Date; import javax.persistence.Entity; /*

为了解决eclipse中未知实体的问题,我整天都在尝试和搜索。 我使用单独的.java和hbm.xml文件

我的实体类是Account.java

// default package
package com.mywebservice.domain;
// Generated Sep 9, 2013 3:55:42 PM by Hibernate Tools 3.4.0.CR1

import java.util.Date;
import javax.persistence.Entity;

/**
 * Account generated by hbm2java
 */


public class Account implements java.io.Serializable {

    private int id;
    private String uid;
    private String empId;
    private String password;
    private Integer status;
    private Integer roleId;
    private String name;
    private String description;
    private String details;
    private String email;
    private Date dateCreated;
    private Date dateModified;
    private String modifiedBy;
    private Integer efpRoleId;
    private Integer isEfp;
    private Integer deptId;
    private Boolean isEpp;
    private Boolean isPasswordNew;
    private Integer statusEpp;

    public Account() {
    }

    public Account(int id) {
        this.id = id;
    }

    public Account(int id, String uid, String empId, String password,
            Integer status, Integer roleId, String name, String description,
            String details, String email, Date dateCreated, Date dateModified,
            String modifiedBy, Integer efpRoleId, Integer isEfp,
            Integer deptId, Boolean isEpp, Boolean isPasswordNew,
            Integer statusEpp) {
        this.id = id;
        this.uid = uid;
        this.empId = empId;
        this.password = password;
        this.status = status;
        this.roleId = roleId;
        this.name = name;
        this.description = description;
        this.details = details;
        this.email = email;
        this.dateCreated = dateCreated;
        this.dateModified = dateModified;
        this.modifiedBy = modifiedBy;
        this.efpRoleId = efpRoleId;
        this.isEfp = isEfp;
        this.deptId = deptId;
        this.isEpp = isEpp;
        this.isPasswordNew = isPasswordNew;
        this.statusEpp = statusEpp;
    }

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUid() {
        return this.uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getEmpId() {
        return this.empId;
    }

    public void setEmpId(String empId) {
        this.empId = empId;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getStatus() {
        return this.status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getRoleId() {
        return this.roleId;
    }

    public void setRoleId(Integer roleId) {
        this.roleId = roleId;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return this.description;
    }

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

    public String getDetails() {
        return this.details;
    }

    public void setDetails(String details) {
        this.details = details;
    }

    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Date getDateCreated() {
        return this.dateCreated;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    public Date getDateModified() {
        return this.dateModified;
    }

    public void setDateModified(Date dateModified) {
        this.dateModified = dateModified;
    }

    public String getModifiedBy() {
        return this.modifiedBy;
    }

    public void setModifiedBy(String modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    public Integer getEfpRoleId() {
        return this.efpRoleId;
    }

    public void setEfpRoleId(Integer efpRoleId) {
        this.efpRoleId = efpRoleId;
    }

    public Integer getIsEfp() {
        return this.isEfp;
    }

    public void setIsEfp(Integer isEfp) {
        this.isEfp = isEfp;
    }

    public Integer getDeptId() {
        return this.deptId;
    }

    public void setDeptId(Integer deptId) {
        this.deptId = deptId;
    }

    public Boolean getIsEpp() {
        return this.isEpp;
    }

    public void setIsEpp(Boolean isEpp) {
        this.isEpp = isEpp;
    }

    public Boolean getIsPasswordNew() {
        return this.isPasswordNew;
    }

    public void setIsPasswordNew(Boolean isPasswordNew) {
        this.isPasswordNew = isPasswordNew;
    }

    public Integer getStatusEpp() {
        return this.statusEpp;
    }

    public void setStatusEpp(Integer statusEpp) {
        this.statusEpp = statusEpp;
    }

}
Account.hbm.xml是

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Sep 9, 2013 3:55:42 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="Account" table="ACCOUNT" schema="dbo" catalog="EPP">
        <id name="id" type="int">
            <column name="ID" />
            <generator class="assigned" />
        </id>
        <property name="uid" type="string">
            <column name="UID" length="50" />
        </property>
        <property name="empId" type="string">
            <column name="EMP_ID" length="50" />
        </property>
        <property name="password" type="string">
            <column name="PASSWORD" length="50" />
        </property>
        <property name="status" type="java.lang.Integer">
            <column name="STATUS" />
        </property>
        <property name="roleId" type="java.lang.Integer">
            <column name="ROLE_ID" />
        </property>
        <property name="name" type="string">
            <column name="NAME" length="50" />
        </property>
        <property name="description" type="string">
            <column name="DESCRIPTION" length="50" />
        </property>
        <property name="details" type="string">
            <column name="DETAILS" length="50" />
        </property>
        <property name="email" type="string">
            <column name="EMAIL" length="50" />
        </property>
        <property name="dateCreated" type="timestamp">
            <column name="DATE_CREATED" length="23" />
        </property>
        <property name="dateModified" type="timestamp">
            <column name="DATE_MODIFIED" length="23" />
        </property>
        <property name="modifiedBy" type="string">
            <column name="MODIFIED_BY" length="50" />
        </property>
        <property name="efpRoleId" type="java.lang.Integer">
            <column name="EFP_ROLE_ID" />
        </property>
        <property name="isEfp" type="java.lang.Integer">
            <column name="IS_EFP" />
        </property>
        <property name="deptId" type="java.lang.Integer">
            <column name="DEPT_ID" />
        </property>
        <property name="isEpp" type="java.lang.Boolean">
            <column name="IS_EPP" />
        </property>
        <property name="isPasswordNew" type="java.lang.Boolean">
            <column name="IS_PASSWORD_NEW" />
        </property>
        <property name="statusEpp" type="java.lang.Integer">
            <column name="STATUS_EPP" />
        </property>
    </class>
</hibernate-mapping>
而且从

package com.mywebservice.utils;

import org.hibernate.Session;
import org.hibernate.Query;
import com.mywebservice.domain.*;
import org.hibernate.annotations.*;

public class HibernateTest {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Session session = SessionFactoryUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        getAccount(session);

    }

    public static void getAccount(Session session) {
        Account acc = new Account();

        acc.setEmpId("123456789");

        session.save(acc);

        System.out.println("Saved!");
    }

}
此外,我还在hibernate.cfg.xml中添加了类的映射

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
        <property name="hibernate.connection.username">sa</property>
        <property name="hibernate.connection.password">hrportal@123</property>
        <property name="hibernate.connection.url">jdbc:sqlserver://HQ-10063332D\SQLEXPRESS;DatabaseName=EPP</property>
<!--         <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property> -->
        <property name="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</property>        

       <property name="hibernate.current_session_context_class">thread</property>

       <mapping class="com.mywebservice.domain.Account" />
    </session-factory>
</hibernate-configuration>

我相信您在hibernate映射中缺少了
属性。尝试更新
hbm
文件中的映射部分,如下所示:

<hibernate-mapping package="com.mywebservice.domain">


您的
帐户
类位于包
com.mywebservice.domain
,因此在
Account.hbm.xml
类中,名称应该是
com.mywebservice.domain.Account
而不仅仅是
Account

如果使用xml配置bean,为什么要使用annotationConfiguration构建会话,可以使用AnnotationConfig进行尝试。may很管用。

回答我自己的问题,所以它将来可能会帮助其他人

在我的hibernate.cfg.xml中,映射应该如下

<mapping resource="com/mywebservice/domain/Account.hbm.xml"></mapping>

而不是

<mapping class="com.mywebservice.domain.Account" />

同样在更正了hibernate.cfg.xml之后,我得到了一个错误 “无法启动默认tuplizer”,为此,我必须添加一个名为javassist.jar的库,它可以工作:)
好运

更新了问题。堆栈跟踪添加您使用的
AnnotationConfiguration
(已弃用)没有注释。您可以使用
hibernate.cfg.xml
而不使用
org.hibernate.cfg.Configuration()
。选择一种方式,两种方式都不起作用。#jesse如果我不使用AnnotationConfiguration对象,它会给出异常“需要使用AnnotationConfiguration实例”
<mapping resource="com/mywebservice/domain/Account.hbm.xml"></mapping>
<mapping class="com.mywebservice.domain.Account" />