Java Hibernate+Spring异常:未知实体

Java Hibernate+Spring异常:未知实体,java,hibernate,spring,spring-mvc,Java,Hibernate,Spring,Spring Mvc,服务器启动时出现异常。服务器是使用Intelij IDE启动的。 我不知道如何修理它。我不熟悉冬眠和春天。提前谢谢 SEVERE: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationMgr' defined in URL [jar:file:/C:/Program%20Files%20

服务器启动时出现异常。服务器是使用Intelij IDE启动的。 我不知道如何修理它。我不熟悉冬眠和春天。提前谢谢

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;
    }
}

谢谢大家的回复。我设法解决了它。这是我的错误。我忘了在xml中添加映射标记

<hibernate-configuration>
    <session-factory>
    <mapping class="com.model.Authentication"/> // i missed this line. after i added it. it worked fine.
    </session-factory>
</hibernate-configuration>

再次感谢。

请添加com.jsi.core.dbservice.model.Authentication Java类好吗?是否将身份验证注释为@Entity bean?是的。我添加了@Entity注释。它是正确的@Entity注释吗?请参阅Spring配置或hibernate映射文件中一定有错误,例如persistence.xml。您需要指导Spring/Hibernate如何查找实体bean。可以添加Spring上下文文件吗?如果有,请添加Hibernate配置文件。