-->
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.  [ 6 posts ] 
Author Message
 Post subject: How to map a "conditional" join using Annotations
PostPosted: Tue Oct 10, 2006 4:12 pm 
Beginner
Beginner

Joined: Sun Sep 24, 2006 11:48 am
Posts: 21
I have a User class and a Picture class.

There is a method called getPictures that returns a Set of <Picture>

public Set<Picture> getPictures();

I would like to add an additional method now that will just return the main picture

public Picture getMainPicture();

Is it possible to do a direct mapping within the Hibernate Annotations?

In this case it would be the picture of the above Set where mainpic=1

Cheers!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 10, 2006 5:07 pm 
Beginner
Beginner

Joined: Tue Oct 10, 2006 3:23 am
Posts: 33
Hi,
Why don't you map another property with a @Where(clause=.. clause and mark it as updateable=false


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 11:07 am 
Beginner
Beginner

Joined: Sun Sep 24, 2006 11:48 am
Posts: 21
Thanks!

have you got an example?

Just spend half an hour googling and could not find any examples for @Where ...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 11:23 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The hibernate annotations unit test suite contains *a lot* of material, actually all the supported mappings

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 11:26 am 
Beginner
Beginner

Joined: Sun Sep 24, 2006 11:48 am
Posts: 21
emmanuel wrote:
The hibernate annotations unit test suite contains *a lot* of material, actually all the supported mappings


Ok, I try to find it.

In the meantime I tried:

Code:
   @Column(name = "mainpic", unique = false, nullable = false, updatable = false)
   @OneToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="uid")
    @Where(clause="mainpic=1")
@NotFound(action=NotFoundAction.IGNORE)
   
   
   public Picture getMainpicture() {
      return this.mainpicture;
   }


however this led to an org.hibernate.ObjectNotFoundException
No row with the given identifier exists: [User#147854]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 1:29 pm 
Beginner
Beginner

Joined: Sun Sep 24, 2006 11:48 am
Posts: 21
Hm..havent found anything :-(


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.