Hi Daryl,
 Thanks for the immediate response.. I have one question.. 
If I use database cascade to do this, will it throw the cache out 
of sync, If I had cached students? I was thinking how will JPA
know that these students are now deleted.

Best Regards,
Srinivasan Krishnamoorthy.



Daryl Stultz wrote:
> 
> On Wed, Oct 14, 2009 at 10:24 AM, Srinivasan Krishnamoorthy <
> [email protected]> wrote:
> 
>>
>> Hi,
>>  I have a manyToOne relation which is unidirectional.
>> For example, say Student and College. Student has manyToOne relation with
>> college. But College do not have OneToMany with Student.
>> Here, if I delete College, I want all the students belonging to it be
>> deleted.
>> Can you please let me know a way to do this with JPA?
>>
>>
> If you want it to be automatic you need to put in the relation
> college.students with CascadeType.DELETE. You can make the getters/setters
> private if you don't want the collection loaded. The only other automatic
> way would be cascade delete on the foreign key in the database. If you
> don't
> need it automatic you can do the delete yourself. (delete from Student s
> where s.college = :college)
> 
> -- 
> Daryl Stultz
> _____________________________________
> 6 Degrees Software and Consulting, Inc.
> http://www.6degrees.com
> mailto:[email protected]
> 
> 

-- 
View this message in context: 
http://n2.nabble.com/Maintaining-foreign-key-relation-in-Unidirectional-ManyToOne-tp3823080p3827043.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to