Skip to Content
avatar image
Former Member

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 03, 2008 at 11:31 AM

    Florian,

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

    -Adrian

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 03, 2008 at 11:54 AM

    See last post

    Add comment
    10|10000 characters needed characters exceeded