-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: @ManyToOne w/ discriminator? Need join tbl w/ 2 IDs + type
PostPosted: Wed Jun 24, 2009 10:22 am 
Newbie

Joined: Tue Sep 20, 2005 3:51 pm
Posts: 18
Location: Boston, MA
Hello All,
I have a relationship I need to model. I wanted to have a join table with 3 IDs and ManyToOne and OneToMany annotations.
Code:
create table folder(
   id primary key
);
create table document(
   id primary key
);
create table type(
   id primary key
);

create table folder_document(
  folder_id references folder(id),
  type_id references type(id), //the same document can be of different types in different folders.
  document_id references document(id),
);


I'd like to model:

Code:
public Class Folder(
  @ManyToOne  //technically, this is a OneToMany in the DB, but logic is enforced by code.
  @JoinTable(name = "folder_document")
  @SomeDiscriminatorColumn(column="type_id", value="foo")
  private Document foo

  @OneToMany
  @JoinTable(name = "folder_document")
  @SomeDiscriminatorColumn(column="type_id", value="bar")
  private List<Document> foo
);

Is there some way of doing it? I have a few relationships that are based on 3 columns.

I know I can do read only JPA objects by creating views and using them as the join table, but I'd have to create the DB rows outside of JPA as JPA wouldn't know to create a row in folder_document with a type value of "foo".

If this is just not doable in JPA, what is the best way to model this manually? Is there a way of creating a manual mapping of the relationship that will allow users to otherwise use JPA functionality?

Thanks in advance,
Steven


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.