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='mraible']
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.
|