-->
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.  [ 11 posts ] 
Author Message
 Post subject: derefenced
PostPosted: Mon Dec 22, 2003 12:00 pm 
Newbie

Joined: Fri Dec 19, 2003 1:08 pm
Posts: 11
I'm feel like I'm close to solving, but keep getting "derefenced" error:

Error:
dereferenced: projectm1_.comp_id.user.username.elements [select distinct projec
t from com.supergloo.database.bean.Projects projects inner join projects.project
members pm where 'x' in elements(pm.comp_id.user.username)]

when trying:

1) session.find("select distinct project from Projects projects inner join projects.projectmembers pm where 'x' in elements(pm.comp_id.user.username)").iterator();

or

2) session.find("select distinct project from Projects projects inner join projects.projectmembers pm where elements(pm.comp_id.user.username) = 'x'").iterator();

Mappings:
<hibernate-mapping>
<class name="com.supergloo.database.bean.Projects" table="projects">

<id name="pid" type="int" column="pid">
<generator class="assigned" />
</id>

<property
name="projectname"
type="java.lang.String"
column="projectname"
length="50"
/>
<property
name="status"
type="java.lang.String"
column="status"
length="50"
/>

... bunch of property elements....

<property
name="accesslevel"
type="java.lang.String"
column="accesslevel"
length="25"
/>

<!-- associations -->
<!-- bi-directional one-to-many association to Projectmembers -->
<set name="projectmembers" lazy="true" inverse="true">
<key>
<column name="pid" />
</key>
<one-to-many class="com.supergloo.database.bean.Projectmembers"/>
</set>

</class>
</hibernate-mapping>

<hibernate-mapping>

<class
name="com.supergloo.database.bean.Projectmembers"
table="projectmembers"
>

<composite-id name="comp_id" class="com.supergloo.database.bean.ProjectmembersPK">
<!-- bi-directional many-to-one association to Projects -->
<key-many-to-one
name="project"
class="com.supergloo.database.bean.Projects">
<column name="pid" />
</key-many-to-one>
<!-- bi-directional many-to-one association to Users -->
<key-many-to-one
name="user"
class="com.supergloo.database.bean.Users"
>
<column name="username" />
</key-many-to-one>
</composite-id>

</class>
</hibernate-mapping>

Using Hibernate 2.1, Postgres 7.3.4

Am I heading in the right direction?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 12:27 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Does this works ?
Code:
select distinct project from Projects projects inner join projects.projectmembers pm where  pm.comp_id.user.username = 'x'

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 12:35 pm 
Newbie

Joined: Fri Dec 19, 2003 1:08 pm
Posts: 11
Thank you. I tried that before posting, but kept getting java.lang.OutOfMemory errors, so I thought I was doing something wrong. Just to double check, I tried again and still receive OoMemory


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 12:43 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
do you implements equals and hashCode in your comp_id class. This is required, have a look at the ref guide (searching for equals)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 12:49 pm 
Newbie

Joined: Fri Dec 19, 2003 1:08 pm
Posts: 11
I think so. I have the following in the com.supergloo.database.bean.ProjectmembersPK class:

public boolean equals(Object other) {
if ( !(other instanceof ProjectmembersPK) ) return false;
ProjectmembersPK castOther = (ProjectmembersPK) other;
return new EqualsBuilder()
.append(this.getProject(), castOther.getProject())
.append(this.getUser(), castOther.getUser())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(getProject())
.append(getUser())
.toHashCode();
}

This was generated from ...hbm2java.CodeGenerator in an Ant task.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 12:56 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
And Projectmembers equals and hashCode refers to the PK ones ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 12:57 pm 
Newbie

Joined: Fri Dec 19, 2003 1:08 pm
Posts: 11
Perhaps related? I also receive an OutofMemory when:

Projects proj = (Projects)session.load(Projects.class, new Integer(id));

Windows 2000 server, over 500MB of RAM, Sun JVM 1.4.2


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 12:59 pm 
Newbie

Joined: Fri Dec 19, 2003 1:08 pm
Posts: 11
Here's from the Projectmembers:

public boolean equals(Object other) {
if ( !(other instanceof Projectmembers) ) return false;
Projectmembers castOther = (Projectmembers) other;
return new EqualsBuilder()
.append(this.getComp_id(), castOther.getComp_id())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(getComp_id())
.toHashCode();
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 1:40 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
todd wrote:
Perhaps related? I also receive an OutofMemory when:

Projects proj = (Projects)session.load(Projects.class, new Integer(id));

Windows 2000 server, over 500MB of RAM, Sun JVM 1.4.2

Let's focus on that.
If you comment the set one-to-many, do you get the OutOfMemory when loading it. Guess not.
Do you see something in the log?

I really suspect a wrong equals implementation, maybe in user

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 1:55 pm 
Newbie

Joined: Fri Dec 19, 2003 1:08 pm
Posts: 11
I really appreciate your help. Thank you. I was thinking of the same thing- concentrate on this:

Projects proj = (Projects)session.load(Projects.class, new Integer(id));

So, since last post this is what I've done:

Removed the foreign key to Users in the Projectmembers table and updated the Projectmembers.hbm.xml from:

<composite-id name="comp_id" class="com.supergloo.database.bean.ProjectmembersPK">
<!-- bi-directional many-to-one association to Projects -->
<key-many-to-one name="project"
class="com.supergloo.database.bean.Projects">
<column name="pid" />
</key-many-to-one>
<!-- bi-directional many-to-one association to Users -->
<key-many-to-one name="user"
class="com.supergloo.database.bean.Users">
<column name="username" />
</key-many-to-one>
</composite-id>

To:

<composite-id name="comp_id" class="com.supergloo.database.bean.ProjectmembersPK">
<key-property
name="username"
column="username"
type="java.lang.String"
length="50"
/>
<!-- bi-directional many-to-one association to Projects -->
<key-many-to-one
name="project"
class="com.supergloo.database.bean.Projects"
>
<column name="pid" />
</key-many-to-one>
</composite-id>


Essentially, changing key-many-to-one to key-property. And now, I'm able to run both session.load(..) and session.find() with expected results and without OutofMemory! That's good progress.

So, I'm just a beginner and do not know anything, but could there be an issue with having multiple (in my case, 2) key-many-to-one elements in a composite-id?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 2:31 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
todd wrote:
So, I'm just a beginner and do not know anything, but could there be an issue with having multiple (in my case, 2) key-many-to-one elements in a composite-id?

I don't know, I'm not fond of composite-id and key-many-to-one is worse to me ;-(

Loading a user give you OutOfMemory ? I still believe User is somehow broken

_________________
Emmanuel


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