I'm fairly new to all this and am having a conceptual problem. I've been wading through documentation, but I'm not even sure where I'm supposed to be looking anymore :S
I had an idea that if I use a base class as below, then users could subclass it for there own logic (storing all data in the map rather than instance variables), and hibernate would be able to persist it without changing the DB structure using a single_table inheritance strategy.
1) Is this idea valid?
2) What association is needed to persist the map? It's a component, right? I was thinking a schema along these lines:
Discount
- Id
DiscountParameter
- DiscountId (foreign key to Discount)
- Key
- Value
I've tried a heap of different things, but can't quite get my head around how OneToMany or ManyToMany relates to this situation.
Thanks,
- Xavier
Hibernate version:
3.1rc2
Mapping documents:
Code:
@Entity
@Inheritance(
strategy=InheritanceType.SINGLE_TABLE,
discriminatorType=DiscriminatorType.STRING,
discriminatorValue="discountType"
)
public abstract class Discount {
private Long id;
private Map<String, String> parameters;
@????
public Map<String, String> getParameters() {
return parameters;
}
public void setParameters(Map<DiscountKey, DiscountValue> parameters) {
this.parameters = parameters;
}
@Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public abstract getDiscountAmount(...);
}