-->
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.  [ 10 posts ] 
Author Message
 Post subject: Optional Many-to-One Relationships???
PostPosted: Fri Dec 10, 2004 7:02 pm 
Beginner
Beginner

Joined: Mon Nov 22, 2004 8:53 pm
Posts: 23
I have a many-to-one relationship and not all of the values in the table are valid. When I retrieve a list of values Hibernate throws an UnresolvableObjectException with a nice message.

The problem is that I would like my app to provide the user the ability to fix the data, so I would like to override this behavior and return null for the field getter instead of blowing up when I retrieve the list.

There have been prior discussions about this, but none that I could find had a solution other then to not use hibernate to deal with the relationships with broken data. There’s even a JIRA request (HB-785), but it’s closed.

Has this been addressed?
Or does anyone have any ideas on how to work around it?

-peter


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 10, 2004 7:59 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
How is it possible ? - is it value in table or prepare data for saving.If you have corect design
(constraint rule) value in table can't invalid
I implement many-to-one with generic lov for user (use foreign key and many-to-one;
swing application) and hibernate work great
I check existance primary key, foreign key for new rows and search foreign keys for persistent row without problem
I don't use one-to-many

regards


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 10, 2004 8:12 pm 
Beginner
Beginner

Joined: Mon Nov 22, 2004 8:53 pm
Posts: 23
snpesnpe wrote:
How is it possible ? - is it value in table or prepare data for saving.If you have corect design
(constraint rule) value in table can't invalid
I implement many-to-one with generic lov for user (use foreign key and many-to-one;
swing application) and hibernate work great
I check existance primary key, foreign key for new rows and search foreign keys for persistent row without problem
I don't use one-to-many

regards


There is not a constraint on the field, and you are correct - there should be and then it would never be a problem. I am mapping a legacy database and have to deal with the bad data provided.

-peter


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 11, 2004 12:07 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
It is problem - it depend from data

regards


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 13, 2004 11:56 am 
Beginner
Beginner

Joined: Mon Nov 22, 2004 8:53 pm
Posts: 23
snpesnpe wrote:
It is problem - it depend from data


That's correct. Unfortunatly I have to deal with bad data, which is beyond my control.
My hope was that there was a reasonable way for hibernate to deal with it.

Throwing an exception is perfect default behavior, as it's what you'd want 90% of the time.
My hope was that there was a way to override this behavior and do something like say return null for the many-to-one field.
That would give my application code an oppertunity to deal with it.

-peter


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 13, 2004 1:37 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
You can try set not-null="true" in many-to-one


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 13, 2004 2:30 pm 
Beginner
Beginner

Joined: Mon Nov 22, 2004 8:53 pm
Posts: 23
snpesnpe wrote:
You can try set not-null="true" in many-to-one


not-null is not an attribute on many-to-one.
i also think it's just used in the schema exports.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 13, 2004 2:38 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
You can set not-null in many-to-one - reference manual is old
I don't try with this field, but it is legal - middlegen add thi sattribute , too (in wrong place, but it isn't important)

regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 5:08 pm 
Newbie

Joined: Tue Jan 18, 2005 10:41 pm
Posts: 15
I have exactly the same problem, inconsistant data in the database. Did you manage to find a solution?

Only solution i can think of is it write some code into the POJO


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 10:49 pm 
Newbie

Joined: Wed Jan 19, 2005 10:37 pm
Posts: 1
I have a table which has a many-to-one and a one-to-many mapping to itslef. It is very much like the category table in the Hibernate in action book example.
this is my table info
name: Container
Column: ID (pk)
Column: name
Column: type
Columh: parentID(fk - which is refrencing the id column in this table)

this is not old database, i have designed it myself and basically it generates a 4 level down tree data.
This is my mapping xml.

<id name="id" type="long" unsaved-value="0" column="id">
<generator class="identity"/>
</id>
<property name="name"/>
<property name="type"/>

<many-to-one
name="parentContainer"
class="Container"
column="PARENTID"
cascade="none"/>

<set name="childContainers" inverse="true" cascade="all-delete-orphan">
<key column="PARENTID"/>
<one-to-many class="Container"/>
</set>

The problem i am having is when i create my first container it complains becuse technically it does not have a parent and it can't have a parent. the very fist level is the root. The parentId gets set to 0 for the top level containers but when reading it, i get exception saying no rows exist with id 0 which is a valid exception. but how can i avoid this? how can i resolve it?
one way that i had it work was to remove the association completely from the mapping and rely on old style queries by getting the children based on the id of the given container....any better idea? any solutions?
thanks.


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