on 09-03-2008 11:07 AM
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
Florian,
the related entity is once named "DummyInfo" and once "PerformanceInfo". Maybe this causes the issue.
-Adrian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
See last post
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.