Person大类的映射文件配置 1 <hibernate-mapping package="com.zh.hibernate.subclass"> 2 3 <class name="Person" table="PERSONS" discriminator-value="PERSONS"> 4 5 <id name="id" type="java.lang.Integer"> 6 <column name="ID" /> 7 <generator class="native" /> 8 </id> 9 10 <discriminator column="TYPE" type="string"></discriminator> 11 12 <property name="name" type="java.lang.String"> 13 <column name="NAME" /> 14 </property> 15 16 <property name="age" type="java.lang.String"> 17 <column name="AGE" /> 18 </property> 19 20 <subclass name="Student" discriminator-value="STUDENT"> 21 <property name="school" type="string" column="SCHOOL"></property> 22 </subclass> 23 24 </class> 25 26 </hibernate-mapping>
查询语句的区别
Hibernate: select person0_.ID as ID1_0_0_, person0_.NAME as NAME3_0_0_, person0_.AGE as AGE4_0_0_, person0_.SCHOOL as SCHOOL5_0_0_, person0_.TYPE as TYPE2_0_0_ from PERSONS person0_ where person0_.ID=? 11, zzqq Hibernate: select student0_.ID as ID1_0_0_, student0_.NAME as NAME3_0_0_, student0_.AGE as AGE4_0_0_, student0_.SCHOOL as SCHOOL5_0_0_ from PERSONS student0_ where student0_.ID=? and student0_.TYPE=‘STUDENT‘
时间: 2024-11-06 09:44:42