我使用union all关键字
从2个相同的表组合了一个Oracle DB视图我使用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 .... -->
我的实体POJO是:
public class Medical {
private Integer id;
//the rest of the common attributes go here ...
}
public class Hospital extends Medical {
private int type = 1;
// the rest of the specific attributes go here
}
问题是当我尝试使用休眠标准API选择选择数据时,Hibernate会生成一个&#34; DELETE&#34; select语句后的语句:
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异常,它不能从DB视图中删除,有时也不会,但是我想知道为什么hibernate生成了delete语句以及它试图删除的实体???
我用来选择数据的代码//每次调用//:
Session currentSession = sessionFactory.openSession();
currentSession.beginTransaction();
Criteria criteria = currentSession.createCriteria(type);
Object output = criteria.list();
session.getTransaction().commit();
session.flush();
session.close();
我的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>
HELP!
提前感谢;