cancel
Showing results for 
Search instead for 
Did you mean: 

SAP JPA - Problem with query and OneToOne relationship

Former Member
0 Kudos

Hello,

I've got a problem with JPA Named Queries. Whenever I query for all Entities of a certain kind, I only get the first one in the ResultList. I think I've singled out that the problem lies with the unidirectional OneToOne relationship since I've tried another entity with such an relationship and the Queries work just fine. This is (the relevant) part of the code.

Owner:


@Entity
@Table(name="Z_DUMMYTYPE")
@NamedQuery(name = "getAllDummyTypes", query = "SELECT d FROM DummyType d")
public class DummyType implements Serializable {
	@Id
	@Column(name = "DUMMYTYPE_ID")
	@TableGenerator(name="IdGenerator", table = "Z_ID_GENERATOR", pkColumnName = "BEAN_NAME", valueColumnName = "MAX_ID")
	@GeneratedValue(strategy=GenerationType.TABLE, generator = "IdGenerator")
	private int dummytypeId;

	@OneToOne(optional = false, cascade = { PERSIST })
	@PrimaryKeyJoinColumn
	@JoinColumn(name = "DUMMY_INFO")
	private DummyInfo dummyInfo;

	@Column(name="DUMMY_NAME")
	private String dummyName;

	@Version
	@Column(name="VERSION")	
	private int version;
        ...

And this is the entity that the relation goes to:


@Entity
@Table(name="Z_DUMMY_INFO")


public class PerformanceInfo implements Serializable {
	@Id
	@Column(name="DUMMY_INFO_ID")
	@TableGenerator(name="IdGenerator", table = "Z_ID_GENERATOR", pkColumnName = "BEAN_NAME", valueColumnName = "MAX_ID")
	@GeneratedValue(strategy=GenerationType.TABLE, generator = "IdGenerator")
	private int dummyInfoId;

	@Version
	@Column(name="VERSION")
	private int version;


	private int dummyAttribute;

Of course I've created the necessary tables and I can persist entities just fine. But when I use the query "getAllDummyTypes", I only get one result regardless how many entities exist in the database. Does anybody know the problem and could help?

Thanks, Florian

Accepted Solutions (1)

Accepted Solutions (1)

adrian_goerler
Active Participant
0 Kudos

Florian,

the related entity is once named "DummyInfo" and once "PerformanceInfo". Maybe this causes the issue.

-Adrian

Former Member
0 Kudos

Hi Adrian,

Oops, that was a typo in my example (unfortunately it seems I can't edit it). I just took the specifics out of my code and replaced it with dummys and missed a spot.

I can persist entities, I can look them up with find(), that's all working. But every time I issue the named query, I only get one result - the first one in the database table. I don't know what I'm doing wrong there.

Thanks for your answer anyway!

EDIT: I don't really know why it was a problem, but I got it working now. Previsiouly, I used Java 5's foreach-loop to got through the result list. After inquiring on the size of the result list, I switched to a for(;;) loop, and voila, it worked. Strange though.

Edited by: Florian Troßbach on Sep 3, 2008 1:52 PM

Former Member
0 Kudos

Hi Florian,

it might be helpful if you provided us with the code that executes the named query.

Best Regards,

Robin

Answers (1)

Answers (1)

Former Member
0 Kudos

See last post