-->
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.  [ 6 posts ] 
Author Message
 Post subject: one to one mapping issues
PostPosted: Thu Apr 19, 2007 9:38 pm 
Newbie

Joined: Thu Apr 19, 2007 8:28 pm
Posts: 3
Hello Hibernate Users,
Iam having the following issue with schema export tool . This is in regard to a one to one mapping. The hibernate version is 3.0

I have two Pojos's (user and user preferences),
The relation ship to be defined between the pojo's is
user <--- bi directional one to one----> user preferences.

The mapping xml file for users is

<hibernate-mapping>
<class
name="com.cpnm.common.dbm.model.User"
table="user"
lazy="false"
>
<id
name="userId"
type="long"
column="user_id"
>

<generator class="native" />
</id>

<version name="version" column="version" type="long" />

<property
name="userName"
type="java.lang.String"
column="user_name"
unique="true"
not-null="true"
/>
<one-to-one
name="preference"
class="com.cisco.cpnm.common.dbm.model.UserPreferences"
property-ref="user"
cascade="all"
>

<column name="user_id"/>
</one-to-one>
</class>
</hibernate-mapping>

The mapping for userPreferences is

<hibernate-mapping>

<class
name="com.cpnm.common.dbm.model.UserPreferences"
table="user_preferences"
lazy="false"
>

<id
name="prefId"
type="long"
column="pref_id"
>

<generator class="native" />
</id>

<version name="version" column="version" type="long" />


<property name="userPreference"
type="java.lang.String"
column="preference"
>
</property>

<!-- Associations -->

<!-- one to one association with users -->

<many-to-one
name="user"
class= "com.cisco.cpnm.common.dbm.model.User"
column = "user_id"
not-null="true"
unique="true"
cascade="none"
/>

</class>

</hibernate-mapping>

I get the following error , while creating a schema using schema-export , it complains about the one to one mapping in the xml mapping file for user.
The error is
"The content of element type "one-to-one" must match "(meta*|formula*)"."
I googled on this, did not find much help.
I tried using a <formula> and <meta> sub element as well , it did not help.
Any insight into this problem ??
thank you,
Suchitha.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 10:52 pm 
Newbie

Joined: Wed Apr 11, 2007 2:11 pm
Posts: 10
Well thanks for your help in my topic so I to took the time to run your xml
through my home made DOM inspector. The problem is hibernate-mapping-3.0.dtd does not declare an element <column> under a
<one-to-one> you can only use only use elements <meta> or <formula>
inside <one-to-one> which are optional here is the segment of the dtd that
refers to this.

Code:
<!-- Declares a one-to-one association between two entities (Or from a component,
component element, etc. to an entity). -->

<!ELEMENT one-to-one (meta*,formula*)>
   <!ATTLIST one-to-one name CDATA #REQUIRED>
   <!ATTLIST one-to-one formula CDATA #IMPLIED>
   <!ATTLIST one-to-one access CDATA #IMPLIED>
   <!ATTLIST one-to-one class CDATA #IMPLIED>
   <!ATTLIST one-to-one entity-name CDATA #IMPLIED>
   <!ATTLIST one-to-one cascade CDATA #IMPLIED>
   <!ATTLIST one-to-one outer-join (true|false|auto) #IMPLIED>
   <!ATTLIST one-to-one fetch (join|select) #IMPLIED>
   <!ATTLIST one-to-one constrained (true|false) "false">
   <!ATTLIST one-to-one foreign-key CDATA #IMPLIED>
   <!ATTLIST one-to-one property-ref CDATA #IMPLIED>
   <!ATTLIST one-to-one lazy (false|proxy|no-proxy) #IMPLIED>
   <!ATTLIST one-to-one node CDATA #IMPLIED>
   <!ATTLIST one-to-one embed-xml (true|false) "true">


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 21, 2007 9:24 pm 
Newbie

Joined: Thu Apr 19, 2007 8:28 pm
Posts: 3
Thank you so much for figuring out the problem , using the "home made" DOM Inspector. It was of gr8 help for me.
hmmm, The xml element <column> is not supported by one to one mapping as per hibernate 3.0 dtd
This issue held me up , from proceeding further for 1.5 days, thanks once gain for your time and help


Top
 Profile  
 
 Post subject: Lazy load One to one relation !!
PostPosted: Sun Apr 22, 2007 3:08 pm 
Newbie

Joined: Sat Mar 03, 2007 3:14 am
Posts: 16
I have a class A that have two one to one relations B,C, when i load class A hibernate load both B,C. I tried with lazy="proxy' or true, but not work for me . !!
Can eny body helpme please .. !!


Top
 Profile  
 
 Post subject: Re: one to one mapping issues
PostPosted: Fri Jul 15, 2011 7:18 am 
Newbie

Joined: Fri Jul 15, 2011 6:54 am
Posts: 3
Hi,

I've tried to map user object to address object like this:

<one-to-one name="address" class="Address">
<column name="address" />
</one-to-one>

but the error is: The content of element type "one-to-one" must match "(meta*,formula*).

Are meta and formula attributes required or optional? If I map user to address replacing one-to-one with many-to-one, there is no problems, I get what I want: I have a User pojo with field Address and Address pojo with no references to User and everything works fine, I'm able to fetch all users and their addresses. I don't have to include anything pointing from Address.java to User.java and nothing referring to User in address.hbm.xml. Because I would also like to have a Company.java pojo to refer to Address.java. With many-to-one mapping this I can do, but it feels wrong to use many-to-one when the logic is one-to-one. I've googled a lot but haven't find a good answer for this. Is there a way to use one-to-one mapping this unidirectional way?

Thanks in advance, Kaitsu


Top
 Profile  
 
 Post subject: Re: one to one mapping issues
PostPosted: Fri Jul 15, 2011 9:06 am 
Newbie

Joined: Fri Jul 15, 2011 6:54 am
Posts: 3
It's well explained in the hibernate tutorial 7.2.2! LoL!

A unidirectional one-to-one association on a foreign key is almost identical (to many-to-one). The only difference is the column unique constraint.

<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
<many-to-one name="address"
column="addressId"
unique="true"
not-null="true"/>
</class>

<class name="Address">
<id name="id" column="addressId">
<generator class="native"/>
</id>
</class>


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

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.