OJB中的多表查询和更新
2008-01-05 08:26:55 来源:WEB开发网核心提示: OJB的文章实在是少的可怜,自己总结了一下一些重点的内容,OJB中的多表查询和更新,想到哪里写到哪里吧 比如有课程(event)和类别
OJB的文章实在是少的可怜,自己总结了一下一些重点的内容。想到哪里写到哪里吧
比如有课程(event)和类别(catalog)两张表,二者是多对多的关系,关系表叫做catalogEventBridge,字段为[catalogID,eventID],现在要做的是一旦查询出一个catalog,就要把相关的event也全部搜索出来。
比如有课程(event)和类别(catalog)两张表,二者是多对多的关系,关系表叫做catalogEventBridge,字段为[catalogID,eventID],现在要做的是一旦查询出一个catalog,就要把相关的event也全部搜索出来。
1.repository_user.xml中作如下定义:
- <class-descriptor class="org.pie.vls.Catalog.Catalog" table="catalog">
- <field-descriptor name="catalogID" column="catalogID" jdbc-type="INTEGER"
- PRimarykey="true" /> <field-descriptor name="catalogName" column="catalogName"
- jdbc-type="VARCHAR" /> <collection-descriptor name="catalogEventList" element-
- class-ref="org.pie.vls.Catalog.CatalogEventBridge" auto-retrieve="true" auto-
- update="true" auto-delete="true"> <inverse-foreignkey field-ref="catalogID"/>
- </collection-descriptor> </class-descriptor> <class-descriptor
- class="org.pie.vls.Catalog.CatalogEventBridge" table="catalogEventBridge">
- <field-descriptor name="catalogID" column="catalogID" jdbc-type="INTEGER"
- primarykey="true" /> <field-descriptor name="eventTypeID" column="eventTypeID"
- jdbc-type="INTEGER" primarykey="true" /> </class-descriptor> <class-descriptor
- class="org.pie.vls.EventType.EventType" table="eventType" > <field-descriptor
- name="eventTypeID" column="eventTypeID" jdbc-type="INTEGER" primarykey="true"
- autoincrement="true" />
- <field-descriptor
- name="eventTypeTitle"
- column="eventTypeTitle"
- jdbc-type="VARCHAR"
- />
- ... ...
- </class-descriptor>
2. bean文件的定义
EventType.java
- public class EventType implements Cloneable, Comparable {
- private String eventTypeTitle;
- private String eventTypeCode;
- private String eventTypeDesc;
- private int eventTypeID;
- public int getEventTypeID() {
- return this.eventTypeID;
- }
- public void setEventTypeID(int value) {
- this.eventTypeID = value;
- }
- ... ...
- }
catalog.java
- public class Catalog implements Comparable {
- private int catalogID;
- private String catalogName = "";
- private List catalogEventList = new Vector();
- /**
- * @return Returns the catalogID.
- */
- public int getCatalogID() {
- return catalogID;
- }
- /**
- * @param catalogID The catalogID to set.
- */
- public void setCatalogID(int catalogID) {
- this.catalogID = catalogID;
- }
- /**
- * @return Returns the catalogName.
- */
- public String getCatalogName() {
- return catalogName;
- }
- /**
- * @param catalogName The catalogName to set.
- */
- public void setCatalogName(String catalogName) {
- this.catalogName = catalogName;
- }
- /**
- * @return Returns the catalogEventList.
- */
- public List getCatalogEventList() {
- return catalogEventList;
- }
- /**
- * @param catalogEventList The catalogEventList to set.
- */
- public void setCatalogEventList(List catalogEventList) {
- this.catalogEventList = catalogEventList;
- }
- }
更多精彩
赞助商链接