-->
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.  [ 2 posts ] 
Author Message
 Post subject: Inner join and composite id
PostPosted: Thu Dec 23, 2004 3:03 pm 
Newbie

Joined: Thu Dec 23, 2004 2:44 pm
Posts: 1
Hello, I'm almost newbie to hibernate. My problem appears when I try to perform an inner join between the two following tables:

PROJECT:
------------
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="com.argojason.fpm.model.Project"
table="project"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version">
<cache usage="read-write" />

<id
name="id"
column="id"
type="java.lang.String"
length="10"
unsaved-value="version">
<generator class="assigned">
</generator>
</id>

<version
name="version"
type="java.lang.Integer"
column="version"
access="property"
unsaved-value="undefined"/>

<property
name="name"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="name"
length="40"
not-null="true"/>

<property
name="state"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="state"
length="20"
not-null="true"/>
</class>

</hibernate-mapping>

USER_PROJECT_PROFILE:
------------------------------
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="com.argojason.fpm.model.UserProjectProfile"
table="user_project_profile"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version">

<composite-id
name="id"
class="com.argojason.fpm.model.UserProjectProfileID">
<key-property
name="userName"
type="java.lang.String"
column="username"
length="20"/>

<key-property
name="projectId"
type="java.lang.String"
column="projectid"
length="10"/>

<key-property
name="profileName"
type="java.lang.String"
column="profilename"
length="20"/>
</composite-id>
</class>

</hibernate-mapping>


As you can see, the second table represents a ternary association between an user, a project and a profile (should I represent it in another way?). I'd like to get a list of Project objects associated to an user (through its username -id-). When I execute the next method (I use Spring) with 'mraible' as username:

public List getProjects(String username) {
return getHibernateTemplate().find("select p from Project p join UserProjectProfile upf where upf.id.userName='" + username + "'");
}

I get this error:

net.sf.hibernate.QueryException: outer or full join must be followed by path expression [select p from com.argojason.fpm.model.Project p join UserProjectProfile upf where upf.id.userName=&apos;mraible&apos;]

I think it could be due to an incompatibility between composite-id's and join, but I'm not sure. Any suggestion about what I'm doing wrong?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 23, 2004 5:08 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
  1. Don't use composite ids if you can avoid it.
  2. Hibernate suport join for mapped associations only. This means you have to change your mapping in order you have an association between user and project.


HTH
Ernst


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