Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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在选择数据时生成的mystirious Delete语句_Java_Oracle_Hibernate - Fatal编程技术网

Java Hibernate在选择数据时生成的mystirious Delete语句

Java Hibernate在选择数据时生成的mystirious Delete语句,java,oracle,hibernate,Java,Oracle,Hibernate,我有一个Oracle DB视图,使用union all关键字从两个相同的表组合而成 我使用hibernate的“每类表继承人”映射在其上创建了一个类树,如下所示: <hibernate-mapping default-lazy="false"> <class name="com.ntg.shefaa.model.impl.Medical" discriminator-value="0" table="MEDICAL_INFORMATIONS" lazy="true"&g

我有一个Oracle DB视图,使用union all关键字从两个相同的表组合而成

我使用hibernate的“每类表继承人”映射在其上创建了一个类树,如下所示:

<hibernate-mapping default-lazy="false">
<class name="com.ntg.shefaa.model.impl.Medical"
    discriminator-value="0" table="MEDICAL_INFORMATIONS" lazy="true">

    <id name="id" type="java.lang.Integer">
        <column name="id" />
        <generator class="identity" />
    </id>

    <discriminator column="TYPE" type="integer" not-null="false" />
<!-- and the rest of the attributes go here .... -->
<subclass name="com.ntg.shefaa.model.impl.Hospital"
        discriminator-value="1">
</subclass>
<!-- and the rest of the subclasses go here .... -->
问题是,当我尝试使用hibernate标准API选择select数据时,hibernate会在select语句之后生成一个“DELETE”语句:

Hibernate: select * from ( 
     select this_.id as id1_2_0_, this_.FACILITY_NAME as FACILITY3_2_0_, this_.FAMOUS_NAME as FAMOUS4_2_0_, this_.GOE_ID as GOE5_2_0_, this_.GOVERNORATE_NAME as GOVERNOR6_2_0_, this_.ADDRESS as ADDRESS7_2_0_, this_.PHONE1 as PHONE8_2_0_, this_.PHONE2 as PHONE9_2_0_, this_.PHONE3 as PHONE10_2_0_, this_.LONGITUDE as LONGITU11_2_0_, this_.LATITUDE as LATITUD12_2_0_, this_.DEGREE as DEGREE13_2_0_, this_.GENDER as GENDER14_2_0_, this_.SPECIALIZATION as SPECIAL15_2_0_, this_.QUALIFICATION as QUALIFI16_2_0_, this_.TYPE as TYPE2_2_0_, clinics2_.ID as ID1_2_2_, clinics2_.FACILITY_NAME as FACILITY3_2_2_, clinics2_.FAMOUS_NAME as FAMOUS4_2_2_, clinics2_.GOE_ID as GOE5_2_2_, clinics2_.GOVERNORATE_NAME as GOVERNOR6_2_2_, clinics2_.ADDRESS as ADDRESS7_2_2_, clinics2_.PHONE1 as PHONE8_2_2_, clinics2_.PHONE2 as PHONE9_2_2_, clinics2_.PHONE3 as PHONE10_2_2_, clinics2_.LONGITUDE as LONGITU11_2_2_, clinics2_.LATITUDE as LATITUD12_2_2_ 
     from MEDICAL_INFORMATIONS this_ 
     left outer join MEDICAL_INFORMATIONS clinics2_ 
     on this_.id=clinics2_.ID and ( clinics2_.type=2) 
) where rownum <= ?

Hibernate: delete from MEDICAL_INFORMATIONS where ID=? and FACILITY_NAME=? and FAMOUS_NAME=? and GOE_ID=? and GOVERNORATE_NAME=? and ADDRESS=? and PHONE1=? and PHONE2=? and PHONE3=? and LONGITUDE=? and LATITUDE=?
我的hibernate配置文件是:

<hibernate-configuration>
<session-factory>
    <!-- <property name="hibernate.hbm2ddl.auto">CREATE</property> -->
    <property name="javax.persistence.validation.mode">NONE</property>
    <property name="show_sql">true</property>
    <property name="format_sql">false</property>
    <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
    <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
    <property name="connection.url">jdbc:oracle:thin:@192.168.3.63:1521/testdb</property>
    <property name="connection.username">tl</property>
    <property name="connection.password">hggi</property>
    <mapping resource="config/Medical.hbm.xml" />
</session-factory>
</hibernate-configuration>

没有一个
真的
假的
org.hibernate.dialen.oracle10galent
oracle.jdbc.driver.OracleDriver
jdbc:oracle:thin:@192.168.3.63:1521/testdb
热释光
hggi
救命啊


提前感谢

这太可怕了,伙计!为什么你打开一个事务(并提交它)只是为了执行一个select语句?@Jorge Campos:我刚刚为所有类型的语句(select-create-update-delete)做了这个,不管怎样:对于select语句,你有什么建议?至少对于不需要事务的select语句来说,这是一个过分的做法。您只需打开一个会话,执行它并关闭它。根据错误的delete语句,我不知道。@Jorge Campos,尽管我看到的所有关于hibernate的示例/教程都为select语句打开事务并关闭它:>>>我听从了你的建议,突然!错误的删除语句消失了!!!非常感谢,先生
Session currentSession = sessionFactory.openSession();
currentSession.beginTransaction();
Criteria criteria = currentSession.createCriteria(type);
Object output = criteria.list();
session.getTransaction().commit();
session.flush();
session.close();
<hibernate-configuration>
<session-factory>
    <!-- <property name="hibernate.hbm2ddl.auto">CREATE</property> -->
    <property name="javax.persistence.validation.mode">NONE</property>
    <property name="show_sql">true</property>
    <property name="format_sql">false</property>
    <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
    <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
    <property name="connection.url">jdbc:oracle:thin:@192.168.3.63:1521/testdb</property>
    <property name="connection.username">tl</property>
    <property name="connection.password">hggi</property>
    <mapping resource="config/Medical.hbm.xml" />
</session-factory>
</hibernate-configuration>