At work we are using hibernate with annotations. So in some places we use the @Embeddable & @Embedded annotation. What do they do? They are both standard annotations, @Embeddable means “this class will not have it’s own table, and it will be embedded in some other’s class table”, and @Embedded means “embed this field to my table”.
That’s all good, but I’ve returned to my old project (klopaj.com), and what do we have there? hbm.xml files. I confess, I’ve first started using hibernate annotations, and then hbm files, so I’m not a hbm guru (nor annotations, but I know a bit more :)). So, to do the same thing with hbm.xml:
<class name="Poi"...> ... <component name="geoPoint" access="field" class="GeoPoint"> <property name="latitude" type="double" /> <property name="longitude" type="double" /> ... </component>
Simple as that, now my Poi table has two additional columns “latitude” and “longitude”, but my Poi class has a reference to GeoPoint instance. :)
But still, I like the annotation solutions prettier, but this one is working as planned.
You know…I still have a dilemma should I blog in English or in Serbian… Mislim da ti makar koji radis Javu bi trebalo da pises na Srpskom ;) E da, i stavi neki syntax highlighting.
I have the same dilemma :)
Actually I wanted to write in Serbian for javasvet, but we’ll see.
A za syntax, stavio sam neki plugin koji zeza. Moraću izgleda sam da hostujem da bi sve radilo kako valja :)
Takođe mislio sam i da imam i na srpskom i na engleskom, a onda sam shvatio da me mrzi da pišem toliko…
Hello Vuk,
I am stuck with same problem ….. Primary Key of my class Test.java (table name Test) is of Type Test_PK.java — Where Test_PK.java has some 3 variables (column) …
Now using annotations it is very easy as I can define like this
@Entity
@Table (———)
public class Test{
@Id
private Test_PK id;
getter & setters
private String l_var;
getter & setters
}
@Embeddable
public class Test_PK{
private String var1;
private String var2;
private String var3;
getters & setters
}
How can I achive this hbm.xml file ???
Can you please Suggest as how to map component as primary key basically as id tag in hbm.xml file
Thanks,
Ritesh
If I understood you correctly, here is how to map your Test class:
Let me know if it helps :)