This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Naming child-parent relation with JPA Annotation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Naming child-parent relation with JPA Annotation" Watch "Naming child-parent relation with JPA Annotation" New topic

Naming child-parent relation with JPA Annotation

maya pedersen

Joined: May 27, 2004
Posts: 6
Hi everybody,

I'm having a slight problem I thought someone might know how to solve:

I have two classes, Element and Article. Element is the abstract parent class of Article and they're tied
together by an id. It's a OneToOne relationship, a given parent can only have one child.

I have JPA autogenerate my tables and my issue is that the constraint between Element and Article, that is
created in the database, has a jibberish name (like 'FK7B3CBC94A2DA0E17'). What I would like is to give said
constraint a name so I have don't have to manually search my db browser to find out what said name is.

I know the @ForeignKey annotation and have used it in other scenarios but it doesn't seem to fit here.

Do any of you guys have any idea how I go about this?

A light version of my classes below:

This is the parent class, Element

This is the child class, Article, connected to it's parent by the ID

Sincere thanks in advance,


live long and prosper
I agree. Here's the link:
subject: Naming child-parent relation with JPA Annotation
It's not a secret anymore!