Hi.
I am using Hibernate Version 2.1.4, and I'd have the following class structure:
Code:
class Page {
public Integer getID();
public void setID(Integer id);
public PageInfo getPageInfo();
public void setPageInfo(PageInfo pageInfo);
public Page getNextPage();
public void setNextPage(Page nextPage);
/*
// Intentionally commented: See description below
public PageInfo getNextPageInfo();
public void setNextPageInfo(Page nextPageInfo);
*/
public byte[] getData();
public void setData(byte[] data);
}
class PageInfo {
public Integer getID();
public void setID(Integer id);
public String getTitle();
public void setTtile(String title);
}
What happen if PageInfo is mapped as a component of the Page, and both of them are mapped to the *same* table? i.e.
Code:
<hiberate-mapping>
<class name="Page" table="Page">
<id name="ID" column="ID" type="int">
<generator class="identity"/>
</id>
<one-to-one name="PageInfo" class="PageInfo" cascade="all"/>
<property name="data"/>
</class>
<class name="PageInfo" table="Page">
<id name="ID" column="ID" type="int">
<generator class="identity"/>
</id>
<property name="Title" />
</class>
</hibernate-mapping>
This mapping may not make sense, but the intention is that the Page class is actually generated for mapping to a XSD and will emit a XML with this format:
Code:
<Page id="1">
<!-- Some Details Omitted -->
<NextPage>
<Page id="2">
<!-- Some Details Omitted -->
</NextPage>
</Page>
</NextPage>
</Page>
The XML is generated by reading the class recursively. This arises a problem that the bulky data[] will also be loaded.
This problem can be solved if we only refers to the next page as a PageInfo.
But normally doing this requires 2 tables for each class.
The question is, what will be the beahviour of Hibernate if the mapping is like this.
Thank you very much.