2

I need SQL query for the below scenario.

2 tables: price & product

price table has ManyToOne relationship with product(i.e., many prices were applicable to one product).

Now I need a query to get only the product details which available in price table.

Note: Using hibernate, I have specified in price as

@ManyToOne @JoinColumn(name = "PRODUCT_ID") private Product product;

But I don't specify OneToMany in product.

2
  • I know that it is not an answer to your question, but why you decided to do it like this? From logic point of view, price is attribute of a product, so logically it should be a field on Product class. If you are willing to keep track of product's price in several shops (for example) you should keep it in Map on some 'Store' class. These are just good manners for anyone who is going to maintain your code. Commented Sep 12, 2015 at 11:38
  • As of now, price holds product_id. But product won't have any relation with price. Commented Sep 12, 2015 at 11:52

1 Answer 1

1

In this case you can return the product attribute in your query, example:

select p.product from price p where p = :price 

Hope this can help. :)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.