5 Replies Latest reply on Sep 23, 2008 1:00 AM by Abhijeet

    Versioning object with embedded property

    Abhijeet Newbie

      I am using an embedded object in my model for representing a many to many relationship. I want to version the association class. Even if I put the @Unversioned annotation to the embedded object, I get the

      Type not supported: org.hibernate.type.ManyToOneType
      exception.

      Is there a way I can deal with this?

        • 1. Re: Versioning object with embedded property
          Adam Warski Master

          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
            Adam Warski Master

            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
              Abhijeet Newbie

              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
                Adam Warski Master

                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
                  Abhijeet Newbie

                  Thanks for your help, Adam. I am defining a surrogate key instead of a composite id.