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.  [ 4 posts ] 
Author Message
 Post subject: mapping a not existing table/column
PostPosted: Sun Oct 15, 2006 8:34 pm 
Beginner
Beginner

Joined: Fri Sep 01, 2006 3:35 pm
Posts: 21
hi.

i've got a mapped entity. let's call it "person". a person has pets. now, i want to load the number of pets into a member of my person class, but i don't want to store the value in a column. i have a simple statement which retrieves all person attributes, and the number of pets.
how do i make hibernate map the resultset of this statement to a class, rather than a table?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 15, 2006 10:46 pm 
Newbie

Joined: Wed Aug 16, 2006 1:13 pm
Posts: 9
Location: Oklahoma
Hibernate maps objects to tables not classes. You could implement a composite user type and use Hibernate to persist it for you. The Manning book, Hibernate Quickly has a good discussion on this topic. See if a friend or associate has a copy of the book and look at composite user types (implements UserType or CompositeUserType). You can google as well.

_________________
Piratepete
david.whitehurst@wisplinx.com


Top
 Profile  
 
 Post subject: Re: mapping a not existing table/column
PostPosted: Sun Oct 15, 2006 11:04 pm 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Add a field to your Person class and map it using formula. Hibernate doesnt create/use columns for entries that are marked with "formula". So for e.g. your hbm.xml for Person woulld have

Code:
<property name="petCount">
    <formula>count(pets)</formula>
</property>


PS: I havent verified if the count is allowed in the formula. The Hibernate docs indicate that it can be .


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 6:06 am 
Beginner
Beginner

Joined: Fri Sep 01, 2006 3:35 pm
Posts: 21
according to google, the formula can be any sql expression. it will be inserted as a subselect.


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