gpt4 book ai didi

java - Hibernate + Spring 异常 : Unknown Entity

转载 作者:行者123 更新时间:2023-12-02 05:10:09 28 4
gpt4 key购买 nike

服务器启动时出现异常。 (服务器使用 Intelij IDE 启动)。我不知道如何解决它。我是 hibernate 和 Spring 的新手。提前致谢。

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

关于java - Hibernate + Spring 异常 : Unknown Entity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6486909/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com