Java 使用Hibernate从数据库检索数据时发生映射错误
我拥有以下实体类别:Java 使用Hibernate从数据库检索数据时发生映射错误,java,database,hibernate,hibernate-generic-dao,Java,Database,Hibernate,Hibernate Generic Dao,我拥有以下实体类别: @Entity @Table(name="TB_CUSTOMER") public class Customer { .... 我还有以下hibernate.cfg.xml: <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
@Entity
@Table(name="TB_CUSTOMER")
public class Customer
{
....
我还有以下hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@**:**:**</property>
<property name="connection.username">***</property>
<property name="connection.password">***</property>
<property name="hibernate.connection.pool_size">20</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<!-- Echo all executed SQL to log -->
<property name="show_sql">false</property>
<mapping class="the.path.of.entity.class.Customer"/>
</session-factory>
</hibernate-configuration>
如果我将findAll方法更改为:
List<Customer> customers = (List<Customer>)this.getCurrentSession().createCriteria(Customer.class).list();
return customers;
List customers=(List)this.getCurrentSession().createCriteria(Customer.class).List();
返回客户;
然后我只得到一张空名单
有人能帮忙吗
也许会话被破坏了
谢谢。将您的主页更改为:
customerDao.openCurrentSession().beginTransaction();
List<Customer> customers = customerDao.findAll();
customerDao.closeCurrentSession();
还要检查映射信息,并在映射中添加Customer类的完全限定名。作为:
<mapping class="package_name.Customer"/>
关于:Query Query=this.getCurrentSession().createQuery(“来自客户C”);我仍然收到“Customer is not mapped”(客户未映射)异常。我尝试将@name注释中的表名替换为Cusomer,因此名称将相同,但不起作用。这张桌子看起来不错。
List<Customer> customers = (List<Customer>)this.getCurrentSession().createCriteria(Customer.class).list();
return customers;
customerDao.openCurrentSession().beginTransaction();
List<Customer> customers = customerDao.findAll();
customerDao.closeCurrentSession();
List<Customer> customers =this.getCurrentSession().createCriteria(Customer.class).list();
Query query = this.getCurrentSession().createQuery("from Customer C");
<mapping class="package_name.Customer"/>