Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA2: How to map only certain table rows to an entity?

I have a table I cannot change with approximately this structure

ID, name, purpose, rubbish...
1, foo, PRICING, ...
2, bar, INVENTORY, ...
3, bar, PRICING, ...

What is the preferred way to map only the lines with purpose=PRICING to an Entity? Is there a way to do this with JPA annotations or do I need a view?

like image 379
Landei Avatar asked Nov 30 '25 15:11

Landei


1 Answers

You might use SINGLE_TABLE inheritance strategy, and use "purpose" as discriminator column like this:

@Entity
@Table(name="THE_TABLE")
@Inheritance(strategy=SINGLE_TABLE)
@DiscriminatorColumn(name="purpose", discriminatorType=STRING)
@DiscriminatorValue("PRICING")
public class Pricing{ ... }
like image 195
adrianboimvaser Avatar answered Dec 03 '25 04:12

adrianboimvaser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!