I'm hoping someone can help -
I'm getting Hibernate to generate my tables for me (using new SchemaExport(config).create(true, true);).
I have about 4 beans (annotated with @Entity) right now - each with an @Id @GeneratedValue id - and Hibernate is creating tables for each of them, which is exactly what I want.
I'm running into issues when I try to persist one of the beans however:
I've created a bean called "Person" which contains an "Address", "Location" and "ContactDetails" (which are separate beans):
e.g. public class Person {
private Address address; private ContactDetails contactDetails; private Location location; (...) }
If I just run it as is (with no extra annotations), I get this error: Could not determine type for: com.example.beans.Address, at table: Person, for columns: [org.hibernate.mapping.Column(address)]
So I've added the @Embedded attribute above the getters for those external entities, like so:
@Embedded public Address getAddress() { [...] } - at least this way hibernate is able to write everything out to the database. However, using @Embeddded means that hibernate "flattens" the bean structure when it creates the table (so the "Person" table contains every field for each of the Entities).
Is there a way to tell hibernate to create joins, so it can mirror the bean structure when it writes out the fields? I guess this must be quite a popular requirement but so far haven't managed to find a way to do this.
Any help / advice appreciated - thanks in advice.
|