Join table with constant value column [message #552113] |
Tue, 10 August 2010 21:58 |
Tommy Odom Messages: 10 Registered: July 2009 |
Junior Member |
|
|
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;
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01942 seconds