The correct mapping depends on whether you want the relationship to be unidirectional or bidirectional. The mapping you have is correct for a bidirectional relationship, you just need to point the mappedBy attribute to the name of the field in the Image class that holds the Category (note that the field in the Category class must be annotated with @ManyToOne). For more details have a look at:
http://www.hibernate.org/hib_docs/annotations/reference/en/html/entity.html#entity-mapping-association-collections starting at section 2.2.5.3.2. In most cases you do not need a join table. It is only recommended if you make the relationship unidirectional, and even then is not required. Mike. On 5/1/07, sionsmith <[EMAIL PROTECTED]> wrote:
Hey everyone - i have a simple persistence mapping question which i am unsure about: I have a Category class which can many images - an image can only be in one category. How do i map this? I've had a go but not sure if i'm correct: ===== Category.class ====== @Entity @Table(name="categories") public class Category extends BaseObject { protected Set<Image> images = new HashSet<Image>(); //getter @OneToMany( targetEntity=Image.class, mappedBy="???" ) public Set<Image> getImages(){ return images; } } ===== Image.class ===== public class Image extends BaseObject { protected Long categoryId; //getter public Long getCategoryId() { return categoryId; } } Thats as far as i have got? Do i need a join table? Surely if the Image object just contains a category ID that will be fine? Any suggestions about how to map this would be very greatful :) Many Thanks Sion -- View this message in context: http://www.nabble.com/javax.persistence-Design-Question-tf3674600s2369.html#a10267807 Sent from the AppFuse - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]