Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

SAP JPA - Problem with query and OneToOne relationship

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

Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question