-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Mapping annotation -> one class per table question
PostPosted: Sat Jun 27, 2009 10:45 am 
Newbie

Joined: Fri May 01, 2009 5:38 pm
Posts: 8
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.


Top
 Profile  
 
 Post subject: Re: Mapping annotation -> one class per table question
PostPosted: Sat Jun 27, 2009 12:02 pm 
Newbie

Joined: Fri May 01, 2009 5:38 pm
Posts: 8
If anyone is following this thread and is interested in the solution:

@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "id")
public Address getAddress() { [...] }

Did exactly what I wanted.

Hth,
A


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.