即使表中存在数据,Hibernate也不会检索数据。直接从SQL Server Management Studio运行查询将显示预期结果。知道我想念什么吗?
Java:
List<User> userCollection= session.createSQLQuery("select column1, column2 from myTable").addEntity(User.class).list();
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>
<property name = "hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name = "hibernate.connection.url">jdbc:sqlserver://server:1433;databaseName=MyDatabase</property>
<property name = "hibernate.connection.username">user</property>
<property name = "hibernate.connection.password">123</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">false</property>
<!-- Drop and re-create the database schema on startup -->
<!-- <property name="hbm2ddl.auto">validate</property> -->
<!-- Names the annotated entity class -->
<mapping class="com.app.User"/>
</session-factory>
</hibernate-configuration>