java - Hibernate Creating Unwanted Mapping Tables -
i creating schema. schema follows
@entity @table(name = "promotion") public class promotion { @id @column (name = "promotion_id") private string promotionid; @joincolumn(name = "seller_id") private list<seller> sellerlist; }; @entity @table(name = "seller") public class seller { @id @column (name = "seller_id") private string sellerid; @manytoone(fetch = fetchtype.lazy) @joincolumn(name = "promotion_id") private promotion promotion; @manytomany(fetch = fetchtype.lazy) @joincolumn(name = "seller_id", referencedcolumnname = "seller_id") private list<sellerpromotion> sellerlist; }; @entity @table(name = "seller_promotion") public class sellerpromotion { @id @column (name = "seller__promotion_id") private string sellerpromotionid; @column(name = "seller_id") private string sellerid; @column(name = "product_id") private string productid; };
problem when executing unit test observing rather 3, total 4 tables getting created.
promotion seller seller_promotion seller_seller_promotioni not sure how 4. 1 getting created. mapping table getting created. when show sql, able see hibernate making joins table (seller_seller_promotion) before joining seller_promotion.
i don't have clue happening. can please help me understand why happening , how prepare ?
the reason why getting because have manytomany relationship between seller , sellerpromotion entities. , way model many many relation have bring together table. why hibernate create table name seller_seller_promotion , have 2 columns per case. each foreign key respective tables.
if interested. hold of book called pro jpa. explains these concepts beautifully in capter object relational mapping.
java hibernate junit hibernate-mapping derby
No comments:
Post a Comment