What you are looking for is called Embeddable .
@Entity public class Fizz { ... @Embedded private Buzz buzz; }
And you can define a mapping file only for Buzz :
<entity-mappings version="1.0" xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"> <embeddable class="...Buzz"> <attributes> <basic name="jupiter"><column name="fizz_buzz_jupiter"/></basic> <basic name="neptune"><column name="fizz_buzz_neptune"/></basic> </attributes> </embeddable> </entity-mappings>
You can include this mapping file in your persistence.xml :
<persistence-unit> <mapping-file>.../orm.xml</mapping-file> </persistence-unit>
If you really want to use annotations for Buzz : you cannot define annotations for other classes. This is the meaning of annotations: they are embedded and belong to their class. Otherwise, there would be no benefit compared to mapping files ...
But you can extend Buzz and use one that has access to properties:
@Entity public class Fizz { ... @Embedded private BuzzExtension buzz; } @Embeddable @Access(AccessType.PROPERTY) public class BuzzExtension extends Buzz { @Column(name="fizz_buzz_jupiter") public int getJupiter() { return super.getJupiter(); } @Column(name="fizz_buzz_neptune") public String getNeptune() { return super.getNeptune(); } }
Only flaw: you cannot use instances of Buzz in Fizz .
source share