-
1. Re: Versioning object with embedded property
adamw Sep 22, 2008 3:53 AM (in response to abhijeetkasale)Hello,
unfortunately, if you've got an @Embeddable class, relations inside it aren't supported - there are some difficulties with this which I don't know yet how to solve. (By the way, the JPA specifications doesn't allow this as well; it's a Hibernate extension).
You can create a JIRA for that :).
--
Adam -
2. Re: Versioning object with embedded property
adamw Sep 22, 2008 3:55 AM (in response to abhijeetkasale)Hello,
reading this again, where do you put the @Unversioned annotation? If you do that, there should be no exceptions. Maybe you can paste some of your code?
--
Adam -
3. Re: Versioning object with embedded property
abhijeetkasale Sep 22, 2008 5:07 AM (in response to abhijeetkasale)Thanks for the quick reply, Adam. Here is the code
@Embeddable //@Versioned public class ProductBankPk implements Serializable { static final long serialVersionUID = 6L; @Unversioned private Company bank; @Unversioned private Product product; @ManyToOne //this throws an Exception public Company getBank() { return bank; } public void setBank(Company bank) { this.bank = bank; } @ManyToOne //this throws an Exception public Product getProduct() { return product; } public void setProduct(Product product) { this.product = product; } } public class ProductBank implements Serializable { static final long serialVersionUID = 7L; @Unversioned private ProductBankPk pk = new ProductBankPk(); @EmbeddedId public ProductBankPk getPk() { return pk; } public void setPk(ProductBankPk pk) { this.pk = pk; } @Transient public Company getBank() { return getPk().getBank(); } public void setBank(Company bank) { getPk().setBank(bank); } @Transient public Product getProduct() { return getPk().getProduct(); } ...... other properties
-
4. Re: Versioning object with embedded property
adamw Sep 22, 2008 7:33 AM (in response to abhijeetkasale)Hello,
well, first of all the current implementation of components (embedded objects) only allows them to be versioned as a whole or not versioned at all, so you can't exclude properties from a component.
Also, the primary key of the entity should be immutable, and is always versioned.
I don't know how much your DB schema is "fixed", but it's always better to have a surrogate key instead of a composite (embedded in your case) id.
And maybe you could try mapping ProductBankPk as a spearate entity?
--
Adam -
5. Re: Versioning object with embedded property
abhijeetkasale Sep 23, 2008 1:00 AM (in response to abhijeetkasale)Thanks for your help, Adam. I am defining a surrogate key instead of a composite id.