wood burning stoves 2.0*
The moose likes JDBC and the fly likes How to generate a unique product id after a cross join Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to generate a unique product id after a cross join" Watch "How to generate a unique product id after a cross join" New topic
Author

How to generate a unique product id after a cross join

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 590




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


Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

My question is: what do you need this single id for?
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 590
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 Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

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

Joined: Aug 02, 2012
Posts: 590
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
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

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.
 
wood burning stoves
 
subject: How to generate a unique product id after a cross join
 
Similar Threads
Restore problem
Hypersonic DB question
Why sql exception happens?
how to increment suufix of this string?
Writing data into existing database