【发布时间】:2019-02-15 14:11:26
【问题描述】:
我正在尝试使用 Hibernate 从 Postgres DB 获取我的实体类的列表。似乎配置中的一切都是正确的,并且所有休眠属性对我来说都很好。
当我调用 findAll 方法时,我得到一个 org.hibernate.exception.SQLGrammarException: could not extract ResultSet
这是我的文件:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.PostgreSQL82Dialect</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost:5433/EES_Settings</property>
<property name="connection.username">postgres</property>
<property name="connection.password">postgres</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.show_sql">true</property>
<!-- C3P0 connection pool -->
<property name="hibernate.c3p0.timeout">600</property>
<property name="hibernate.c3p0.maxIdleTimeExcessConnections">20</property>
<!-- Connection testing settings -->
<property name="hibernate.c3p0.validate">false</property>
<property name="hibernate.c3p0.idle_test_period">30</property>
<property name="hibernate.c3p0.automaticTestTable">conTestTable</property>
<mapping class="com.deere.isg.easyequipmentsetup.easyequipmentsetup.entities.Configuration" resource="Mappers/Configuration.hbm.xml"/>
</session-factory>
</hibernate-configuration>
@Id
@Column(name = "guid")
private String guid;
@Column(name = "profile_name")
private String profileName;
@Column(name= "machine_id")
private String machineId;
@Column(name= "implement_id")
private String implementId;
@Column(name= "creation_date")
@Type(type="timestamp")
private Timestamp creationDate;
@Column(name= "modification_date")
@Type(type="timestamp")
private Timestamp modificationDate;
List<Configuration> configurations = (List<Configuration>) getCurrentSession().createSQLQuery("select Cast(guid as varchar) guid, profile_name, machine_id, implement_id, creation_data, modification_date from ees_configuration").list();
预期结果是数据库中记录的集合,实际结果是提到的异常。
【问题讨论】:
-
始终分享完整的 stactrace
-
为什么你使用原生 SQL 而不是 HQL?
标签: java postgresql hibernate