I've got a table which is in one-to-one relationship with several other tables and I can't find a way to map it correctly in Hibernate. The reason why I need so many tables is that I need to store various XML documents (valid to various XML schemas) in Oracle XMLType columns using structured storage. Unfortunately, only one XML schema can be related to a single XMLType column.
I followed the example at
http://www.hibernate-examples.com/2009/12/one-to-one-association-using-primary.htmlIn
Scenario.java I have
Code:
public class Scenario implements java.io.Serializable {
...
private String scenarioName;
private String mimetype;
private ScenarioType scenarioDoc;
... // getter and setter methods
In
ScenarioType.java, I have a reference to Scenario object:
Code:
public class ScenarioType implements java.io.Serializable {
private Scenario scenario;
private int scenarioId;
private Document scenarioXml;
... // getter and setter methods
Then I used
one-to-one element in
Scenario.hbm.xml:
Code:
<one-to-one name="scenarioDoc" class="cz.zcu.kiv.eegdatabase.data.pojo.ScenarioType" cascade="save-update"/>
The following changes were made in
ScenarioType.hbm.xml:
Code:
<id name="scenarioId" type="int">
<column name="SCENARIO_ID" precision="22" scale="0"/>
<generator class="foreign">
<param name="property">scenario</param>
</generator>
</id>
<one-to-one name="scenario" class="cz.zcu.kiv.eegdatabase.data.pojo.Scenario" constrained="true"/>
When I compile the project, I get the following error:
Quote:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/persistence.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: persistent class not known: cz.zcu.kiv.eegdatabase.data.pojo.ScenarioType
But everything seems to be set right in
persistence.xml:
Code:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
...
<property name="mappingLocations" value="classpath*:cz/zcu/kiv/eegdatabase/data/pojo/*.hbm.xml" />
...
I also want to map one class into more (identical) tables, so I changed the mapping file
ScenarioType.hbm.xml as in the example here:
http://stackoverflow.com/questions/4997950/map-two-identical-tables-same-schema-to-same-entity-in-hibernateHowever, the compilation fails even when mapping one class into a single table...