-->
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: Possible to map an 1:n relation on the n (not in code) side?
PostPosted: Tue May 19, 2009 12:52 pm 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
Hi,

if I map a 1:n relation on the 1-side, I will get an Jointable as Databasetable.
Which I would prefer, cause of performance issues, is to map it on the n-side, without changing my java code. (unidirectional relation instead of bidirectional)
So on the n-side of the relation there is no attribut present, so no foreign key attribute is present in my javacode. Can I annotate the list in a way that the n-side gets implicit an foreign-key-attribute, rather than an join table?

Is this possible? How is this done with annotations?

E.g.:
Code:
@OneToMany(cascade = javax.persistence.CascadeType.ALL, fetch = FetchType.LAZY)
private List<PdfFile> listOfPdfs;


Code:
@Entity

@org.hibernate.annotations.Entity(dynamicUpdate = true)
public class PdfFile implements SupportsDatabaseId {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Lob
    private String filename;

    @Lob
    private String comment;

     /* Cause of postgreSql problems with BLOB's */   
    @Type(type = "org.hibernate.type.BinaryType")
    private byte[] pdf;


So I would like to store the id of the object, which contains the list in the PdfFile without adding a attribute for it.

Thanks.

Greetings Michael


Top
 Profile  
 
 Post subject: Re: Possible to map an 1:n relation on the n (not in code) side?
PostPosted: Tue Aug 18, 2009 5:27 am 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
Hello, by coincidence I have discovered that,
that defining a
@JoinColumn on the @OneToMany side is enough to give hibernate the hint to map it on the other side.

Also the position attribute will be mapped by the other table.

Greetings Michael


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.