Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Mike Ring
Orphan Records in UserGroupRole Table?
January 31, 2012 7:36 AM
Answer

Mike Ring

Rank: New Member

Posts: 16

Join Date: December 18, 2007

Recent Posts

I'm using Liferay 5.2.3 and finding orphan records in the UserGroupRole table. Either userids are changing or users are being actually deleted and not just deactivated. I would assume that, if all were well, the query:

SELECT userid, groupid, roleid
FROM usergrouprole ugr where ugr.userid not in (select ut.userid from user_ ut);

Should return no results, while I'm getting about 2400 rows. It looks like most of the orphan userids are users with the community member role in the guest community, but that's not all of them (and why would that be happening to start with?) I'm getting errors related to fetching usergrouprole objects by role and/or group, and then I error out when I try to find the associated user.
David H Nebinger
RE: Orphan Records in UserGroupRole Table?
January 31, 2012 8:20 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6126

Join Date: September 1, 2006

Recent Posts

The Liferay database does not use foreign keys nor automatic deletions.

You should not be accessing the database directly.

You should be going through the Liferay API to access this information, and you will not have the orphan records to worry about.
Mike Ring
RE: Orphan Records in UserGroupRole Table?
January 31, 2012 8:27 AM
Answer

Mike Ring

Rank: New Member

Posts: 16

Join Date: December 18, 2007

Recent Posts

I'm not accessing the database directly, except to confirm what I learned by accessing via API. I'm looking for users from a particular organization that have a particular organization role. Thus, I use: UserGroupRoleLocalServiceUtil.getUserGroupRolesByGroupAndRole. That returns a list of UserGroupRole objects, which have the method getUser(). When I call getUser() on an orphaned UserGroupRole object, the whole thing crashes and burns with the exception: com.liferay.portal.NoSuchUserException: No User exists with the primary key <primary key>.

Right now I'm just going to catch the exception and move on, but it makes me wonder what is happening to these user objects to cause the UserGroupRole objects to be orphaned--are the userIDs changing or are the users getting completely deleted?