-->
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: Weak Association, Optional Entity Relation By Foreign Key
PostPosted: Tue Jul 21, 2009 4:10 pm 
Newbie

Joined: Tue Jul 21, 2009 3:45 pm
Posts: 1
I have a use-case that calls for a weak association. Consider a domain object M
and another domain object V. The life-cycle of these objects are completely independent.
V wants to "monitor" M, but it allowable for M to be deleted while being monitored
by V.

We are using JPA annotations and using Hibernate to generate our schema.

Using any kind of hibernate association between M and V results in foreign key
constraints that prevent us from deleting M while V has a reference to it. We
receive a foreign key constraint violation from the DB (Postgres).

I have tried just about everything, including the obvious (setting "nullable" to "true"
on the @JoinColumn, trying to use an association table via @JoinTable, setting
"optional" to "true" on a @OneToOne, trying a @ManyToOne....)

I have also tried to use @Formula to specify SQL, but the result set is not returned
in the target object class.

I could use a @NamedQuery, but our domain objects do not have a reference to
the session or session factory.

Basically I want Hibernate to fetch on object by foreign key, and if it is not there,
return null.

For now, we are just storing the surrogate key in our domain object V, and then
doing a query each time.... but that defeats our goal of having this managed
by Hibernate.


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.