• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to generate a unique product id after a cross join

 
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




Notice that p.ProductCode is no longer unique, how do I identify each
Product separately?
Given that Texture has groups of Subtextures and
has to cross join with the product table so that
each combination of texture and subtexture has
its product in its type...

Update:
I thought, is that the way to go, concatenate each id from each table??...
Thanks

Update2:
The problem is I don't know how to define a unique price for each item
Jack


 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My question is: what do you need this single id for?
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Vajsar wrote:My question is: what do you need this single id for?



I want to define each product, so that when I click on a product JComboBox



Like
Texture I have gold, silver and bronze
and subtexture I have a, b, c
and product I have necklace, ring etc

So that I will get something like
gold-a-necklace and its unit price.... $1,000

when I click on

gold-b-ring and its unit price $2,000

when I click on

silver-a-necklace and its unit price is $500

and so on so forth

Thanks
Jack



 
Martin Vashko
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Will you store these compound products in a table? It would be especially useful if not all possible combinations would represent an existing products. Say that you never have a bronze ring, but you can have a bronze doorknob. In this case, there probably would be a table of all existing products. This table would have its own surrogate primary key, and three attributes - foreign keys to the texture, subtexture and products table. Only combinations that represent an actual product would be in this table. Problem solved!

If you don't ever need to represent every such combination in the database, one possible way would be to store these combinations in Java objects which would have attributes for texture id, subtexture id and product id. The equality methods (equals(), hashCode(), compareTo() etc.) would consider all there attributes. If you implement a toString() method to return the representation to be used in the GUI, you can put these objects directly into the combobox. When user chooses one, you read the texture, subtexture and product from it and use it the way you need.

I guess that the first option is what you want, but I can't be sure, of course, since I don't know your entire requirements.

Note: you're using a single term - "product" - in two different meanings. Once as a basic type of product - eg. "necklace" or "ring", and yet again for a completed product - say "golden necklace with subtexture a". This makes not only speaking about it with someone, but also thinking about the entire concept problematic. I'd suggest to devise two different terms for these two meanings.
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think your solution is the only way to go, since I have about 20 groups of textures and subtextures, and 10 "products", it is just too tedious to map them out all, thanks
 
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A bit more precisely, I recommend using a random key in your HTML that maps to a unique identifier in your DBMS table, and the table has as many columns/attributes as you need.

Never expose an internal id out to HTML. To not try to "encode" meaning in the identifier, you want a dataless key.
 
reply
    Bookmark Topic Watch Topic
  • New Topic