-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Using OneToMany Join with Composite Key and Transient Fields
PostPosted: Tue Jun 03, 2008 11:30 am 
Newbie

Joined: Tue Jun 03, 2008 11:01 am
Posts: 1
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;


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.