-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to map one-to-one relationship for multiple tables?
PostPosted: Tue May 10, 2011 5:05 pm 
Newbie

Joined: Tue May 10, 2011 4:49 pm
Posts: 1
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.html

In 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-hibernate
However, the compilation fails even when mapping one class into a single table...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.