Hibernate + Spring 异常:未知实体

2024-03-11

服务器启动时我遇到异常。 (服务器使用 Intellij IDEA 启动)。 我不知道如何解决它。我是休眠和春季的新手。提前致谢。

SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationMgr' defined in URL [jar:file:/C:/Program%20Files%20(x86)/Apache%20Software%20Foundation/Tomcat%207.0/webapps/ROOT/WEB-INF/lib/dbservice-1.0-SNAPSHOT.jar!/ApplicationContext-Service.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'authenticationDao' threw exception; nested exception is org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: com.jsi.core.dbservice.model.Authentication; nested exception is org.hibernate.MappingException: Unknown entity: com.jsi.core.dbservice.model.Authentication
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1361)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4681)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5184)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5179)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
    at java.lang.Thread.run(Thread.java:619)
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'authenticationDao' threw exception; nested exception is org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: com.jsi.core.dbservice.model.Authentication; nested exception is org.hibernate.MappingException: Unknown entity: com.jsi.core.dbservice.model.Authentication
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358)
    ... 21 more

认证实体

/**
 * Authentication Entity - Representation of the db table
 */
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Entity
@Table(name = "t_authentication")
public class Authentication extends LongBaseEntity implements Serializable{

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "auth_id")
    private Long mAuthId;

    @Column(name = "authentication_id")
    private Long mAuthenticationId;

    @Column(name = "tcn")
    private Long mTcn;

    @Column(name = "audit_comment")
    private String mAuditComment;

    @Column(name = "last_timestamp")
    private Date mLastTimeStamp;

    @Column(name = "user_id")
    private Long mUserId;

    @Column(name = "authentication_date")
    private Date mAuthenticationDate;

    @Column(name = "hostname")
    private String mHostname;

    @Column(name = "ip_address")
    private String mIpAddress;

    @Column(name = "referrer_url")
    private String mReferrerURL;

    @Column(name = "session_id")
    private String mSessionId;

    public Long getAuthId() {
        return mAuthId;
    }

    public void setAuthId(Long pAuthId) {
        this.mAuthId = pAuthId;
        mId = pAuthId;
    }

    public Long getAuthenticationId() {
        return mAuthenticationId;
    }

    public void setAuthenticationId(Long pAuthenticationId) {
        this.mAuthenticationId = pAuthenticationId;
    }

    public Long getTcn() {
        return mTcn;
    }

    public void setTcn(Long pTcn) {
        this.mTcn = pTcn;
    }

    public String getAuditComment() {
        return mAuditComment;
    }

    public void setAuditComment(String pAuditComment) {
        this.mAuditComment = pAuditComment;
    }

    public Date getLastTimeStamp() {
        return mLastTimeStamp;
    }

    public void setLastTimeStamp(Date pLastTimeStamp) {
        this.mLastTimeStamp = pLastTimeStamp;
    }

    public Long getUserId() {
        return mUserId;
    }

    public void setUserId(Long pUserId) {
        this.mUserId = pUserId;
    }

    public Date getAuthenticationDate() {
        return mAuthenticationDate;
    }

    public void setAuthenticationDate(Date pAuthenticationDate) {
        this.mAuthenticationDate = pAuthenticationDate;
    }

    public String getHostname() {
        return mHostname;
    }

    public void setHostname(String pHostname) {
        this.mHostname = pHostname;
    }

    public String getIpAddress() {
        return mIpAddress;
    }

    public void setIpAddress(String pIpAddress) {
        this.mIpAddress = pIpAddress;
    }

    public String getReferrerURL() {
        return mReferrerURL;
    }

    public void setReferrerURL(String pReferrerURL) {
        this.mReferrerURL = pReferrerURL;
    }

    public String getSessionId() {
        return mSessionId;
    }

    public void setSessionId(String pSessionId) {
        this.mSessionId = pSessionId;
    }

    public String toString() {
        return "Payment{" +
                "mId=" + getId() +
                ", mIpaddress=" + mIpAddress +
                '}';
    }

}

DAO 类:

/**
 * Implementation for AuthenticationMgr DAO layer.
 *
 */
import com.jsi.core.dbservice.model.Authentication;
import com.jsi.core.dbservice.model.JSIException;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import java.sql.SQLException;
import java.util.List;
public class AuthenticationDao extends HibernateDaoSupport implements IAuthenticationDao {

    @Override
    public List<Authentication> list() {
        final String query = "Select a from Authentication a order by a.id desc";
        return (List<Authentication>) getHibernateTemplate().executeFind(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                return session.createQuery(query).list();
            }
        });
    }

    @Override
    public void save(Authentication authentication) throws JSIException {
        getHibernateTemplate().save(authentication);
    }

    @Override
    public Authentication load(Long id) {
        return getHibernateTemplate().load(Authentication.class, id);

    }

    @Override
    public void update(Authentication authentication) throws JSIException {
        getHibernateTemplate().update(authentication);
    }

    @Override
    public void delete(Long id) {
        getHibernateTemplate().delete(load(id));
    }
}

如果您碰巧使用 HibernateUtil 来操作数据,则需要将带注释的类添加到您的配置中。

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {
    private static final SessionFactory sessionFactory;
    static {
        try {
            sessionFactory = new AnnotationConfiguration().addAnnotatedClass(Authentication.class)
            .configure()
                    .buildSessionFactory();
        } catch (Throwable ex) {
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}

http://docs.jboss.org/hibernate/stable/annotations/reference/en/html/ch01.html http://docs.jboss.org/hibernate/stable/annotations/reference/en/html/ch01.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Hibernate + Spring 异常:未知实体 的相关文章

随机推荐

  • 当应用程序无法处理深层链接时如何优雅地回退到网站

    情况 您有一个内容广泛的移动网站 m somewhere com 在 Google Play 上 您有一个 Android 应用程序 它复制了 m somewhere com 的主要功能 但不是全部 您的客户 雇主 投资者要求您为应用程序可
  • 在 bootstrap/compiled.php 中找不到 Laravel 4 类

    我已经使用 Git 创建了一个新分支 对我的代码应用了一些更新 在我的临时服务器上检查了该分支 现在我无法运行任何与 Composer 相关的内容 我已经在composer json中添加了一些新的包 这些包适用于我的开发环境 但是一旦我尝
  • 计算一下从 167.37 美元开始找零的不同方式?

    这是一个面试问题 给定一个金额 例如 167 37 美元 找到使用该货币可用面额为该金额找零的所有可能方法 任何人都可以想到一种空间和时间高效的算法和支持代码 请分享 这是我编写的代码 工作 我正在尝试找到它的运行时间 感谢任何帮助 imp
  • 未解析的 Aapt 错误

    在将我计划使用的图像添加到drawables文件夹后 我试图构建我的android应用程序 该项目之前运行得很好 但运行该项目后 出现一条错误消息 显示 Unparsed Aapt Error 该错误显示在 src 文件夹中 我尝试清理我的
  • 安装并加载“rJava”

    由于 rJava 的加载问题 我在加载 Deducer 包时遇到问题 rJava 的安装似乎正确完成 但在调用它加载时却失败了 拜托 有人可以提供一些智慧之光吗 错误 rJava 的 loadNamespace 中的 onLoad 失败 详
  • 如何在没有缩略图的情况下发布 Facebook 链接?

    我想使用以下方式发布 Facebook 链接图形API http developers facebook com docs reference api post 但我希望能够避免使用缩略图 Facebook 的网络界面在发布图像时有一个无缩
  • 在服务中注册接收者

    我有一个service可以从以下位置启动和停止button 但在service我想注册一个接收器来监听短信广播 我只想要service在运行时监听短信 我试过registerReceiver receiver intentfilter 但这
  • 每当输入文本时应用程序崩溃,无法识别的选择器发送到实例

    每当我尝试在文本字段上书写时 我都会遇到这个奇怪的错误 使用我的应用程序会崩溃 NSNull fastCStringContents unrecognized selector sent to instance 0x108e3eaf0 Te
  • 如何在 JavaScript 中正确地将对象从 for 循环推送到数组?

    我想通过 for 循环创建一个包含对象的数组 但有一个问题 我想要的形状如下 data apple label Fruits data banana label Fruits data mango label Fruits 所以我尝试了以下
  • 在 Pytorch 中获取负片(倒置)图像

    我想直接从数据加载器获取图像的负片并将其作为张量提供 有我可以使用的库吗 我试过火炬transforms并没有找到任何 不要费力 只需使用255 image它会给你一个负面的形象 试试吧
  • htaccess 阻止对目录的访问,但允许对文件的访问

    我有这样的情况 我正在 Zend Framework 中开发应用程序 htaccess 指向每个请求 索引 php 如果请求路径上存在某个文件或目录 则 htaccess 允许访问这些文件 例如 css js 图像等 现在我有这样的链接 e
  • std::vector::resize() 与 std::vector::reserve()

    评论区里有一个话题这个帖子 https stackoverflow com a 13017983 1629821关于使用std vector reserve vs std vector resize 这是原始代码 void MyClass
  • 两个自定义(角度)元素之间的通信

    两个自定义 角度 元素之间的通信 假设有两个自定义元素 login button
  • 关于类类型静态数组的空初始化

    当我运行静态代码分析器 QACPP 时 我收到警告 根据 QACPP 文档 初始化为 0 仅适用于内置类型 初始化类型对象的数组A 必须使用 如下 int i 5 0 Only works with built in types A a 5
  • SQL 查询性能和 dropcleanbuffers

    有一个你必须运行的 最佳实践 DBCC FREESESSIONCACHE DBCC FREEPROCCACHE DBCC DROPCLEANBUFFERS 在对 SQL 查询进行性能分析之前 然而 例如后一个 DROPCLEANBUFFER
  • 如何开始信息提取?

    您能否推荐一个培训路径来开始并变得非常擅长信息提取 我开始阅读它是为了做我的一个爱好项目 很快意识到我必须擅长数学 代数 统计 概率 我读过一些关于不同数学主题的入门书籍 而且非常有趣 寻找一些指导 请帮忙 更新 只是为了回答其中一条评论
  • 向 Google Play Android Developer API 发出 HTTP post 请求

    我正在尝试授权 Google Play Android Developer API 我正处于需要发出 HTTP POST 请求以交换访问令牌和刷新令牌的授权代码的步骤 Google https developers google com a
  • 地图中的键类型不匹配:预期 .. 文本,收到 ... LongWritable

    我有一个简单的 hadoop 应用程序 它获取一个 CSV 文件 然后用 分割条目 然后计算第一个项目 以下是我的代码 package com bluedolphin import java io IOException import ja
  • 创建 webdriver 后 Selenium firefox 配置文件更新下载目录

    我想知道启动驱动程序后如何更新 更改 selenium 中的下载位置 在创建配置文件和启动网络驱动程序期间设置下载目录不是问题 启动 webdriver 根据数据类型更改目录后会出现此问题 例如 如果dl doc是word保存在Docs W
  • Hibernate + Spring 异常:未知实体

    服务器启动时我遇到异常 服务器使用 Intellij IDEA 启动 我不知道如何解决它 我是休眠和春季的新手 提前致谢 SEVERE Context initialization failed org springframework be