-->
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.  [ 3 posts ] 
Author Message
 Post subject: Is possible to restrict composite-id in mapping file?
PostPosted: Wed Oct 31, 2007 12:48 pm 
Beginner
Beginner

Joined: Tue Oct 30, 2007 7:57 am
Posts: 47
Hibernate version 3.2.5
Database MySQL

I have a class with a composite-id (relation table), and i need to add some restrictions to the possilbe values. I'd like to know if there is any way to restrict it in mappig files (I prefer not to do it by code). The mapping file is:

Code:
    <class name="CarOption" table="CAR_OPTION">
      <composite-id name="pk" class="CarOptionPK">
         <key-many-to-one name="modelOption" class="cars.ModelOption">
            <column name="OPTION_ID" />
            <column name="MODEL_ID" />
         </key-many-to-one>
         <key-many-to-one name="car" column="CAR_ID" class="cars.Car"/>         
      </composite-id>
      <property name="value" column="VALUE" type="integer" not-null="false"/>
    </class>


The restriction is that modelOption.pk.model, must equal car.model

Is there any way to add it in the mapping file?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 02, 2007 9:50 pm 
Newbie

Joined: Tue Sep 04, 2007 2:21 pm
Posts: 14
In the class tag you can define a where attribute.

From the reference doc...
(12)
where (optional) specify an arbitrary SQL WHERE condition to be used when retrieving objects of this class

HTH
Tom


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 05, 2007 4:33 am 
Beginner
Beginner

Joined: Tue Oct 30, 2007 7:57 am
Posts: 47
TomAtoms wrote:
In the class tag you can define a where attribute.

From the reference doc...
(12)
where (optional) specify an arbitrary SQL WHERE condition to be used when retrieving objects of this class

HTH
Tom


It seems useful, but only when retrieving data, not when storing it. Thank you anyway. I am learning hibernate, and just wanted to know what is possible.


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