Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate映射无法提取结果集_Java_Postgresql_Hibernate - Fatal编程技术网

Java Hibernate映射无法提取结果集

Java Hibernate映射无法提取结果集,java,postgresql,hibernate,Java,Postgresql,Hibernate,我正在尝试使用Hibernate从Postgres DB获取实体类的列表。看起来配置中的一切都是正确的,所有hibernate属性对我来说都很好 @Id @Column(name = "guid") private String guid; @Column(name = "profile_name") private String profileName; @Column(name= "machine_id") private String machineId; @Column(name=

我正在尝试使用Hibernate从Postgres DB获取实体类的列表。看起来配置中的一切都是正确的,所有hibernate属性对我来说都很好

@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;
当我调用findAll方法时,我得到一个org.hibernate.exception.sqlgrammareexception:无法提取结果集

@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;
这是我的文件:

<!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 configurations=(List)getCurrentSession().createSQLQuery(“选择转换(guid为varchar)guid、配置文件名称、机器id、实现id、创建数据、修改日期(来自ees_配置”).List();

预期结果是从DB收集记录,实际结果是提到的异常。

尝试使用条件和方法列表检索为实体存储的所有记录:

@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 = getCurrentSession().createCriteria(Configuration.class).list();
List configurations=getCurrentSession().createCriteria(Configuration.class).List();
如果您使用ORM(在您的例子中是Hibernate),则不建议使用sql查询

@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;

或者,如果您喜欢使用Sql查询并只提取bean的某些列,请使用
addScalar
以所需类型绑定所有列

始终共享完整的stactrace为什么使用本机Sql而不是HQL?请不要回答
尝试这样做:
。解释你做了什么以及为什么
@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;