I have two classes, CalculatedValue and Price. Price has map of CalculatedValue. Each CalculableValue instance has name, value and couple of other fields.
Here is mapping I use to describe a dependency between Price and the CV:
@OneToMany(
cascade = CascadeType.ALL,
fetch = FetchType.EAGER
)
@JoinColumn(name = "priceId")
private Map<String, CalculatedValue> calculatedValues =
new TreeMap<String, CalculatedValue>();
No join table, just mapping by priceId column which refers to Price unique Id.
Here is how generated table looks like:
CREATE TABLE PUBLIC.CALCULATEDVALUE ( UNIQUEID BIGINT NOT NULL, KEY VARCHAR(2147483647) NOT NULL, PRICEID BIGINT, VALUE DOUBLE NOT NULL, CALCULATEDVALUES_KEY VARCHAR(2147483647), PRIMARY KEY (UNIQUEID) );
ALTER TABLE PUBLIC.CALCULATEDVALUE ADD FOREIGN KEY (PRICEID) REFERENCES TEST.PUBLIC.PRICE (UNIQUEID);
Everything is working, but I want to know if it possible to to this:
- Avoid automatic "CALCULATEDVALUES_KEY" column creation. I already have this value stored in KEY column and it would be nice to avoid duplication and somehow give a hint to JPA.
- Trigger cascade delete of calculable value for each removed price (in case I'm running SQL delete statement)
- Will such mapping work in case I'll use Date as a key? Not for this particular field, but for a bunch of other ones it will be useful. Assuming the same OneToMany relationship.
Thank you in advance!
PS. I'm using latest version of EclipseLink & H2 as database. PPS. Didn't want to store the calculable values in array since I need to often find it buy key in Java.