Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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
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
Author

Naming child-parent relation with JPA Annotation

maya pedersen
Greenhorn

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,

Maya


live long and prosper
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Naming child-parent relation with JPA Annotation