0 Replies Latest reply on Feb 26, 2008 11:27 AM by yanfengzhang816

    JPA, Embedded class containing an entity class, Help!

    yanfengzhang816

      I got several classes like below in my project which uses JPA as persistence layer:

      //an entity class
      class Country{
       Long id;
       String name;
      }
      
      //an embedded class (a.k.a component)
      class Address{
       Country country; //many to one mapping here
       String province;
       String street;
      }
      
      //an entity class
      class Person{
       Long id;
       Address homeAddress; //which is an embedded class here, I used AttributeOveride annotation here
       Address workingAddress; //also an embedded class
      }
      


      I used AttributeOverride to map Address class into Person class. But, unfortunately, the homeAddress and workingAddress is mapped as RAW colums in oracle database -- it is unacceptable for my DBA.

      How can I generate a right mapping for this situation? It would be nice if the Person class could be mapped as the follwoing:
      Table Person(
       id integer,
       homeAddress_country integer, --id of the country entity for home address
       homeAddress_province varchar2,
       homeAddress_street varchar2,
       workingAddress_country integer, --id of the country entity for working address
       workingAddress_province varchar2,
       workingAddress_street varchar2,
      )


      I read the hibernate annotation document. It mentioned an example in which the Country class is also an embedded class and said that JPA does not support AttributeOverride for embedded class within an embedded class. (http://www.hibernate.org/hib_docs/annotations/reference/en/html/entity.html#d0e531).

      My question is that:
      1. Does hibernate support this kind of mapping?
      2. If yes, can I mix hibernate annotation and JPA annotation in a JavaEE project which is targetted to running on JBoss platform? what specific jars should I import?

      Any ideas?

      Thanks in advance!!