Hi every one.
This is my Table structure...
Tbl_Products
Product_id (primary key)
Product_name
Subcategory_name
And
Tbl_Car
Product_id (primary key)
Fuel_Type
Horse_Power
And
Tbl_Tv
Product_id (primary key)
No_Of_Channels
Tv_Type
I need to provide a relationship between these tables. Hence I use the OneToOne relation between the product table and all other subcategory tables. Following is my table entity bean classes.
Code:
@Entity
@Table(name="TBL_PRODUCTS")
public class TblProducts implements Serializable
{
@Id
@Column(name="PRODUCT_ID")
private BigDecimal productId;
@OneToOne(fetch=FetchType.LAZY,mappedBy="productId")
private TblCar tblCar;
@OneToOne(fetch=FetchType.LAZY,mappedBy="productId")
private TblTv tbltv;
}
@Entity
@Table(name="TBL_TV")
public class TblTv implements Serializable
{
@Id
@Column(name="PRODUCT_ID", insertable=false, updatable=false)
private BigDecimal productId2;
@OneToOne(optional=false)
@JoinColumn(name="PRODUCT_ID")
private TblProducts productId;
}
@Table(name="TBL_CAR")
public class TblCar implements Serializable
{
@Id
@Column(name="PRODUCT_ID", insertable=false, updatable=false)
private BigDecimal productId2;
@OneToOne(optional=false)
@JoinColumn(name="PRODUCT_ID")
private TblProducts productId;
}
I am not sure if this relation is correct or wrong.
Assuming, I have to fetch the Tbl_products information along with Tbl_car. I execute the following query.
select * from Tbl_product where subcategory_name =’car’
The results flashed are as expected but the query is performed on other sub-category tables also like Tbl_tv as observed in my console. No results are however fetched from other sub-cateogory tables; however.
But I am apprehensive about this logic for any performance issues that might crop-up. The concern is more as we have 10 different subcategories related with the product table with 10,000 records in it.
by
Thiagu.m