2 hutiefang hutiefang 于 2014.04.25 16:22 提问

hiberante4.3.5 session.get()报错

Exception in thread "main" org.hibernate.MappingException: Unknown entity: ProdTaMasterEntity
at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1096)
at org.hibernate.internal.SessionImpl.locateEntityPersister(SessionImpl.java:2565)
at org.hibernate.internal.SessionImpl.access$1900(SessionImpl.java:176)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.(SessionImpl.java:2504)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.(SessionImpl.java:2495)
at org.hibernate.internal.SessionImpl.byId(SessionImpl.java:1038)
at org.hibernate.internal.SessionImpl.get(SessionImpl.java:960)
at frank.hu.webHibernate.dao.TaMasterDao.getById(TaMasterDao.java:39)
at frank.hu.webHibernate.dao.TaMasterDao.main(TaMasterDao.java:45)

问题在于我的list方法正常执行无任何错误get就不行 什么原因
方法如下。

  public List<ProdTaMasterEntity> list(){
      Session session=  sessionFactory.openSession();
      logger.info("openSession");
      logger.debug("openSession");
      logger.warn("wwwwwwww");
      logger.error("eeeeeeeeee");
      Query query=  session.createQuery("from ProdTaMasterEntity" );

      List<ProdTaMasterEntity> list=      query.list();
      session.close();
      logger.debug("close Session");
     // sessionFactory.close();
      return list;

  }

  public ProdTaMasterEntity getById(String id){
      Session session=  sessionFactory.openSession();
      ProdTaMasterEntity ta=      (ProdTaMasterEntity) session.get("ProdTaMasterEntity", id);
    //  session.close();
      return ta;
  }
  public static void main(String[] args) {
      TaMasterDao tmd=new TaMasterDao();
      tmd.getById("1205020129");
}

我是使用的注解
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import java.util.Date;

/**

  • ProdTaMaster generated by hbm2java
    */
    @Entity
    @Table(name = "PROD_TA_MASTER")
    public class ProdTaMasterEntity implements java.io.Serializable {

    // Fields

    /**

    • */ private static final long serialVersionUID = -8968765405025406974L; @Id @Column @GeneratedValue( strategy=GenerationType.AUTO
      ) private String tmTaNo;

其他只有getset方法

如果改为 (ProdTaMasterEntity) session.get(ProdTaMasterEntity.class, id);又正确了。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!