-->
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.  [ 2 posts ] 
Author Message
 Post subject: Struggling with straight forward onetomany
PostPosted: Mon Feb 13, 2012 6:22 am 
Newbie

Joined: Wed Nov 30, 2011 7:06 am
Posts: 6
I have an Incident class and an IncidentItem class.
Each Incident should have one or more IncidentItems.
I have setup the following, but when I try to retrieve an Incident the IncidentItems collection is always empty.

Java:
Incident
...
@Id
@Column(name="OID")
@NotFound(action=NotFoundAction.EXCEPTION)
private Integer oid = -1;

@OneToMany (mappedBy="incident",fetch=FetchType.EAGER)
private Set<IncidentItem> incidentItems = new HashSet<IncidentItem>();
...

IncidentItem
...
@Id
@Column(name="OID")
@NotFound(action=NotFoundAction.EXCEPTION)
private Integer oid = -1;

@ManyToOne
@JoinColumn(name = "OWNER_OID")
private Incident incident = null;
...

Of course each class has relevent getter/setter methods.

Database (OID is the primary key column in each table):
INCIDENT {OID*, various boring fields}
INCIDENTITEMS {OID*, various boring fields, OWNER_OID} - where OWNER_OID refers to the @oid field of the Incident class


I'm happy table names etc are ok as not getting errors in logs about mapping to non-existant fields/tables or anything like that. The Incident objects are being populated ok with data from other fields, just not the IncidentItems collection.

I've tried using Set and List as the type for the incidentitems within the incident object.

Given the choice I'd like to aim at only using JPA annotations, but I'm at a point in this project now where I just have to get it working regardless of desire to stick to JPA over Hibernate annotations.


Top
 Profile  
 
 Post subject: Re: Struggling with straight forward onetomany
PostPosted: Mon Feb 13, 2012 8:37 am 
Newbie

Joined: Wed Nov 30, 2011 7:06 am
Posts: 6
Hibernate appears to be trying to do a join on the two tables, but not getting any results back (I have checked, the owner_id column in incidentitems tables does contain relevant data for the incident I'm trying to retrieve).


Hibernate: select incident0_.OID as col_0_0_ from INCIDENTS incident0_ where OID='15112'
Hibernate: select incident0_.OID as OID20_1_, incident0_.NAME as NAME20_1_, incident0_.PRIORITY as PRIORITY20_1_, incident0_.SHORTCUT as SHORTCUT20_1_, incidentit1_.OWNER_OID as OWNER3_20_3_, incidentit1_.OID as OID3_, incidentit1_.OID as OID14_0_, incidentit1_.IDTAG as IDTAG14_0_, incidentit1_.OWNER_OID as OWNER3_14_0_ from INCIDENTS incident0_ left outer join INCIDENTITEMS incidentit1_ on incident0_.OID=incidentit1_.OWNER_OID where incident0_.OID=?

Running the above query via SQL tool returns 3 rows (as expected) but that data isn't getting into the java collection.


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