Hi All, I need some help please.
I want to map the tables below. The problem, is that when i create the schema from hibernate. The product_table is created with "localLanguage", and "localeVariant" colums, which should not be there.
When i get the region for a product, i want the "localLanguage" and "localeVariant" values to be picked up from the transient variables declared in the ProductBo Object.
i.e. i should be able to do the following, and the correct region should be returned.
Code:
ProductBo prod = new ProductBo();
prod.setLocaleLanguage("en");
prod.setLocaleVariant("cm");
prodDAO.getProduct(prod, 12L);
Region reg = prod.getRegion;
How do i do this?
(I understand that this is not good database design.)
One Product has One Region. A region can belong to many products. Each region, could have many values, depending on the lanaguage and variant values.
product_table*product_id
region_id
region_table*region_id
*locale_lanaugage
*locale_variant
value
(* represents the Primary Key or Composite Primary key in the region_table)
The Hibernate mappings are as follows:
Product Object
Code:
@Entity
@Table(name="product_table")
public class ProductBo implements Serializable
{
/***/
private static final long serialVersionUID = 1979081245218313935L;
@Transient
private String localLanguage;
@Transient
private String localeVariant;
@Id
@GeneratedValue
@Column(name="productid")
private Long id;
@ManyToOne
@JoinColumns({
@JoinColumn(name="region_id", referencedColumnName="region_id"),
@JoinColumn(name="localeLanguage", referencedColumnName="locale_language"),
@JoinColumn(name="localeVariant", referencedColumnName="locale_variant")
})
private RegionType region;