• Post Reply Bookmark Topic Watch Topic
  • New Topic

composite-id Query

 
Venkatesh Lakshmana
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Group,

i have 2 Classes:

MainClass
ComponentPK
Value
Comment

ComponentPK
ID1
ID2
KeyName

and i need to create a SQL query like
(assuming class name = database table name)

SELECT ComponentPK.Keyname, Value, Comment FROM MainClass, ComponentPK WHERE
ComponentPK.ID1 = 2 AND ComponentPK.ID2 = 3

How to create the same Query with

createQuery or CreateCriteria functions, ID1 & ID2 can be variables.



Thanks in advance
Venkatesh

(Eclipse SDK
Version: 3.1.2
Build id: M20060118-1600
Hibernate Plugin 0.9.6)


heres xml class description


<class
name="MainClass"
table="mainclass"
>
<meta attribute="sync-DAO">false</meta>
<composite-id name="Id" class="ComponentPK">
<key-property
name="ID1"
column="ID1"
type="integer"
/>
<key-property
name="ID2"
column="ID2"
type="integer"
/>
<key-property
name="KeyName"
column="KeyName"
type="string"
/>
</composite-id>

<property
name="Value"
column="Value"
type="string"
not-null="true"
length="255"
/>
<property
name="Comment"
column="Comment"
type="string"
not-null="true"
length="255"
/>


</class>
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can make your PK class implement the CompositeUserType and now you will be able to query on those two attributes.

Mark
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!