Join table with constant value column [message #552113] |
Tue, 10 August 2010 17:58  |
Eclipse User |
|
|
|
I'm attempting to map on top of a set of existing tables defined by XRMS (an open source CRM) and I'm having trouble figuring out the best way to set up a JPA mapping that I was hoping I could get some advice on.
There are 2 tables that I am trying to map via a join table. The source table is companies and has a column named company_id. The destination table is categories which has a category_id. There is a join table named entity_category_map which has a category_id, on_what_id, on_what_table. The on_what_id would be the company_id in this case and the on_what_table would be set to 'company'.
What I can't figure out is how to define a constant value for the on_what_table join column. I found online that OpenJPA supports this by specifying the constant value in the referencedColumnName like below:
@ManyToMany
@JoinTable(
name="entity_category_map", schema="crm",
joinColumns={@JoinColumn(name="on_what_id", referencedColumnName="company_id"),
@JoinColumn(name="on_what_table", referencedColumnName="'company'")},
inverseJoinColumns=@JoinColumn(name="category_id", referencedColumnName="category_id")
)
public List<Category> getCategories() {
return categories;
}
public void setCategories(List<Category> categories) {
this.categories = categories;
}
|
|
|
|
Re: Join table with constant value column [message #552776 is a reply to message #552557] |
Fri, 13 August 2010 09:22  |
Eclipse User |
|
|
|
Thanks for the feedback. I hadn't looked at the DescriptorCustomizer before, that definitely looks like it would work.
For now I just ended up creating a view of the join table since it's only being used as read-only right now.
|
|
|
Powered by
FUDForum. Page generated in 0.02307 seconds