-->
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.  [ 6 posts ] 
Author Message
 Post subject: Once again problems with duplicate entries...
PostPosted: Sun Sep 04, 2005 4:35 pm 
Newbie

Joined: Tue Aug 09, 2005 10:29 am
Posts: 10
Howdy all!

I've got a real simple table, a primary key (player_id) and 2 columns (property_code. value). There are several entries with the same primary key. I try to retrieve all entries by a 'from player_property p where p.player_id=<some number>'. The result set is the right size but the data in the set are copies of the first found entry. I've tried to figure this one out to no avail. I'm sure this is easy, please somebody help me out here.

cheers
Erik

Hibernate version:
2.1
Mapping documents:
Using xdoclet
Code between sessionFactory.openSession() and session.close():
/*
* @hibernate.class table="@NETWORK_PLAYER_BETA_SCHEMA@.player_property"
*
*/

public class PropertyDO {
private Integer playerId;
private String propertyCode;
private String value;

/**
*
* @hibernate.id column="player_id" generator-class="assigned"
* @return Returns the playerId.
*/
public Integer getPlayerId() {
return playerId;
}
/**
* @param playerId The playerId to set.
*/
public void setPlayerId(Integer playerId) {
System.out.println("PropertyDO.setPlayerId:"+playerId);
this.playerId = playerId;
}

/**
*
*
* The actual data. Could be crypted.
*
* @hibernate.property column = "property_code"
*
* @return Returns the propertyCode.
*/
public String getPropertyCode() {
return propertyCode;
}
/**
* @param propertyCode The propertyCode to set.
*/
public void setPropertyCode(String propertyCode) {
this.propertyCode = propertyCode;
}
/**
* @hibernate.property column = "value"
* @return Returns the value.
*/
public String getValue() {
return value;
}
/**
* @param value The value to set.
*/
public void setValue(String value) {
this.value = value;
}

}

Name and version of the database you are using:
MySQL 4.0
The generated SQL (show_sql=true):
from com.ongame.naps.service.core.playeradmin.impl.PlayerPropertyDO pp where pp.playerId = 1
Hibernate: select propertydo0_.player_id as player_id, propertydo0_.property_code as property2_, propertydo0_.value as value from network_player_beta.player_property propertydo0_ where (propertydo0_.player_id=? )


Top
 Profile  
 
 Post subject: Re: Once again problems with duplicate entries...
PostPosted: Sun Sep 04, 2005 6:52 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
erik_svensson wrote:
There are several entries with the same primary key.


What do you mean by "entries"? If you mean rows, check the database and make sure your "primary key" is actually a primary key.

PK values are unique.


Top
 Profile  
 
 Post subject: Re: Once again problems with duplicate entries...
PostPosted: Mon Sep 05, 2005 12:41 am 
Newbie

Joined: Tue Aug 09, 2005 10:29 am
Posts: 10
dennisbyrne wrote:
erik_svensson wrote:
There are several entries with the same primary key.


What do you mean by "entries"? If you mean rows, check the database and make sure your "primary key" is actually a primary key.

PK values are unique.


I mean columns.
There are two primary keys and the player_id is one of them.
The thing is, is that the result set is the correct size. The columns in the result set, however, are all the first column found. In fact, it's the same object. (ie if I do list.get(0) == list.get(1) it evaluates to true).


Top
 Profile  
 
 Post subject: Re: Once again problems with duplicate entries...
PostPosted: Mon Sep 05, 2005 12:43 am 
Newbie

Joined: Tue Aug 09, 2005 10:29 am
Posts: 10
erik_svensson wrote:
dennisbyrne wrote:
erik_svensson wrote:
There are several entries with the same primary key.


What do you mean by "entries"? If you mean rows, check the database and make sure your "primary key" is actually a primary key.

PK values are unique.


I mean columns.
There are two primary keys and the player_id is one of them.
The thing is, is that the result set is the correct size. The columns in the result set, however, are all the first column found. In fact, it's the same object. (ie if I do list.get(0) == list.get(1) it evaluates to true).


I forgot to add that quering the db from the command line gives the correct result.

cheers

/Erik


Top
 Profile  
 
 Post subject: Re: Once again problems with duplicate entries...
PostPosted: Mon Sep 05, 2005 1:00 am 
Pro
Pro

Joined: Fri Sep 02, 2005 4:21 am
Posts: 206
Location: Vienna
Hi,

erik_svensson wrote:
There are two primary keys and the player_id is one of them.


Sorry but I don't understand this statement - to the best of my knowledge a table can only have one PK.

Do you mean that the primary key consists of two columns and player_id is one of them? If so, what's the other part of the PK? Otherwise, please post the create statements for your table.

Erik


Top
 Profile  
 
 Post subject: Re: Once again problems with duplicate entries...
PostPosted: Tue Sep 06, 2005 9:03 am 
Newbie

Joined: Tue Aug 09, 2005 10:29 am
Posts: 10
ErikFK wrote:
Hi,

erik_svensson wrote:
There are two primary keys and the player_id is one of them.


Sorry but I don't understand this statement - to the best of my knowledge a table can only have one PK.

Do you mean that the primary key consists of two columns and player_id is one of them? If so, what's the other part of the PK? Otherwise, please post the create statements for your table.

Erik


Problem solved. I needed a composite key. And yes, there are two columns designated as primary key.


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