-->
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.  [ 11 posts ] 
Author Message
 Post subject: 1-to-1, no ids, foriegn keys - I feel dumb
PostPosted: Sun Mar 21, 2004 10:16 pm 
Newbie

Joined: Sun Mar 21, 2004 9:27 pm
Posts: 5
Hi.

I'm trying to get a 1-to-1 mapping to work but I can't.

Basically, I've got an object that contains another object - unidirectional. Neither of these objects have ids. Incidently, they're JAXRPC generated.

I cannot for the life of me work out how to make this simple scenario happen. I've even gone so far, god forbid, to look at the code of ForeignGenerator!

My hbm file follows.

<hibernate-mapping>
<class name="LoadHP" table="LoadHotelPrices">
<id column="id" type="long">
<generator class="native"/>
</id>
<one-to-one name="rr" class="DKRoomRate"/>
</class>

<class name="DKRoomRate" table="RoomRates_Parent">
<id column="LoadHotelPricesType_id" type="long">
<generator class="foreign">
<param name="property">id</param>
</generator>
</id>
<property name="maxRoomMix" column="maxRoomMix"/>
</class>
</hibernate-mapping>

Do I need to have some association from DKRoomRate back to LoadHP?

regards,
dk-


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 21, 2004 11:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
<hibernate-mapping>
<class name="LoadHP" table="LoadHotelPrices">
<id column="id" type="long">
<generator class="native"/>
</id>
<one-to-one name="rr" class="DKRoomRate"/>
</class>

<class name="DKRoomRate" table="RoomRates_Parent">
<id column="LoadHotelPricesType_id" type="long">
<generator class="foreign">
<param name="property">lhp</param>
</generator>
</id>
<property name="maxRoomMix" column="maxRoomMix"/>
<one-to-one name="lhp" class="LoadHP"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: Not looking good.
PostPosted: Sun Mar 21, 2004 11:27 pm 
Newbie

Joined: Sun Mar 21, 2004 9:27 pm
Posts: 5
hmm.. What would you say if I said, "it didn't work"?

I get this error.

net.sf.hibernate.PropertyNotFoundException: Could not find a getter for lhp in class DKRoomRate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 21, 2004 11:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Obviously, you need to add a new property to your class, to make the association bidirectional!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 12:19 am 
Newbie

Joined: Sun Mar 21, 2004 9:27 pm
Posts: 5
But I don't want the association bi-directional. How do I make it work unidirectional?

The truth be told, I can't make it bi-directional, it's a generated class, out of Apache Axis.

regards,
dk-


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 12:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Actually, I should have said:

<one-to-one name="lhp" class="LoadHP" constrained="true"/>

of course.

Quote:
But I don't want the association bi-directional. How do I make it work unidirectional?


This is almost always a mistake, especially for the entity which owns the foreign key constraint. I think you need to rethink your object model here. Its just a bad design that will come back to bite you later on.

Your object model is important and should not be driven by whatever crap Apache Axis spits out :)

However, if you insist, then the solution is to not use the foreign id generator and manually ensure primary key equality by assigning ids to the DKRoomRate instances.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 1:33 am 
Newbie

Joined: Sun Mar 21, 2004 9:27 pm
Posts: 5
hmm..

It's not working with the " constrained="true" " addition either.

Actually, whilst rereading your post, I come to another interpretation. Are you saying that the one-to-one mapping cannot do this automagically, and I -need- to set it up manually?



Quote:
This is almost always a mistake, especially for the entity which owns the foreign key constraint.


why? link (because I'm sure you've had to explain this before)?[/quote]


Top
 Profile  
 
 Post subject: a bit more
PostPosted: Mon Mar 22, 2004 1:45 am 
Newbie

Joined: Sun Mar 21, 2004 9:27 pm
Posts: 5
> However, if you insist, then the solution is to
> not use the foreign id generator and manually
> ensure primary key equality by assigning ids to
> the DKRoomRate instances.

I just tried to do this, and it occured to me that I don't have any id members in my classes.

So, to reiterate,

- no ids,
- no bidirectionality
- cannot change code

But I still want to maintain FK consistency in a one-to-one manner. Any other ways of achieving this?

To give you bigger picture, I'm trying to use the axis generated classes as DTOs - save me thousands and thousands of lines of mundane code. In truth, I'm trying to use XMLBeans, but there is no 0-arg constructor, so I've had to fallback to axis.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 1:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
I just tried to do this, and it occured to me that I don't have any id members in my classes


Code:
public interface Session extends Serializable {

   /**
    * Persist the given transient instance, using the given identifier.
    *
    * @param object a transient instance of a persistent class
    * @param id an unused valid identifier
    * @throws HibernateException
    */
   public void save(Object object, Serializable id) throws HibernateException;



Code:
Foo foo = new Foo();
Bar bar = new Bar();
foo.setBar(bar);

Serializable id = session.save(foo);
session.save(bar, id);


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 3:07 pm 
Newbie

Joined: Wed Mar 24, 2004 7:40 pm
Posts: 18
This is the part of the thread that I desparately want the answer to:

deniskrizanovic:
Quote:
But I don't want the association bi-directional. How do I make it work unidirectional?


gavin:
Quote:
This is almost always a mistake, especially for the entity which owns the foreign key constraint.


deniskrizanovic:
Quote:
why? link (because I'm sure you've had to explain this before)?


gavin <javadocs from the Session interface>

Is Gavin's last post in answer to this question or at least related to it? I am mystified by it. Can someone help me with this?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 05, 2004 3:57 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
dannwebster wrote:
Is Gavin's last post in answer to this question or at least related to it? I am mystified by it. Can someone help me with this?

Not related.
It is related to
Quote:
I just tried to do this, and it occured to me that I don't have any id members in my classes

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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.