Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Naming child-parent relation with JPA Annotation

 
maya pedersen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic