openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daryl Stultz <da...@6degrees.com>
Subject Re: Maintaining foreign key relation in Unidirectional ManyToOne
Date Wed, 14 Oct 2009 14:36:11 GMT
On Wed, Oct 14, 2009 at 10:24 AM, Srinivasan Krishnamoorthy <
srinivasan.krish@live.com> 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:daryl@6degrees.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message