I have 2 tables in database User and Link. The userid is a foreign in the link table. I have used hibernate reverse engg xml to create the model classes in java.
It has created the User, Link, LinkId class. Here the Link class links the 2 tables, while LinkId contains the attributes of Link.
I am trying to query the link table using the userid. The query I have is “createQuery(
“from com.paypal.socialpay.models.LinkId li where li.userid=?”).setInteger(0, id).list();”
But on execution of the query I get “java.lang.IllegalArgumentException: No positional parameters in query: from com.paypal.socialpay.models.LinkId li where li.userid=?”
Can someone tell me what I am doing wrong
class name="com.paypal.socialpay.models.Link" table="link" catalog="socialdb">
<composite-id name="id" class="com.paypal.socialpay.models.LinkId">
<key-property name="id" type="int">
<column name="id" />
</key-property>
<key-property name="userid" type="java.lang.Integer">
<column name="userid" />
</key-property>
<key-property name="title" type="string">
<column name="title" length="100" />
</key-property>
<key-property name="price" type="string">
<column name="price" length="100" />
</key-property>
<key-property name="description" type="string">
<column name="description" length="500" />
</key-property>
<key-property name="contentname" type="string">
<column name="contentname" length="100" />
</key-property>
<key-property name="contentpreviewname" type="string">
<column name="contentpreviewname" length="100" />
</key-property>
<key-property name="contentdisplayname" type="string">
<column name="contentdisplayname" length="100" />
</key-property>
<key-property name="contentpreviewdisplayname" type="string">
<column name="contentpreviewdisplayname" length="100" />
</key-property>
<key-property name="downloadlink" type="string">
<column name="downloadlink" length="100" />
</key-property>
<key-property name="contentsavelocation" type="string">
<column name="contentsavelocation" length="150" />
</key-property>
<key-property name="previewsavelocation" type="string">
<column name="previewsavelocation" length="150" />
</key-property>
</composite-id>
<many-to-one name="user" class="com.paypal.socialpay.models.User" update="false" insert="false" fetch="select">
<column name="id" not-null="true" />
</many-to-one>
</class>
Try to use this:
UPDATE: I believe the mapping should look like this:
etc. with properties, not
<key-property>sThe query doesn’t work because you’re trying to select from a LinkId – which is not entity, but a key of Link. Probably some reverse engineering issue.