Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » @OneToMany Annotation problem(@OneToMany does not fetch list)
@OneToMany Annotation problem [message #899863] Thu, 02 August 2012 16:17 Go to next message
Lars Drießnack is currently offline Lars DrießnackFriend
Messages: 9
Registered: August 2012
Junior Member
Hi,

I've got a problem with a @ManyToOne and @OneToMany Annotation.

@Entity
@Table(name = "MYT_Team")
public class Team extends Named implements Serializable {

 ...
 @OneToMany(mappedBy = "team", cascade = CascadeType.ALL, fetch = FetchType.EAGER,  targetEntity = Player.class)
 private Set<Player> players = new HashSet<Player>();
 ...
}

@Entity
@Table(name = "MYT_Player")
public class Player extends Human {
 ...
 @ManyToOne(fetch = FetchType.EAGER)
 private Team team;
 ...
}


I created a JUnit test for this and persisted the team and than the players. On database everthing looks fine. When i then load the team I allways get an empty Set. I also tried to call .size() on the set to force the loading and I tried it with an @JoinTable and @JoinCOlumn annotation. Nothing is working. In some cases {IndirectSet: not instantiated} is written inside of the set.

A Similar issue was discussed here: stackoverflow.com/questions/8301820/onetomany-relationship-is-not-working without any solution.

Does somebody have an idea how to fix this bug?

kind regards
Lars
Re: @OneToMany Annotation problem [message #900023 is a reply to message #899863] Fri, 03 August 2012 13:41 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello,

Have you put annotations on properties and fields by chance? This might cause the mappings with the fetchtype set to EAGER to be ignored since they should be all on fields or all on properties. Try setting the EclipseLink log level to FINEST and search the logs for where the players and team mappings are processed to see what might be going on. This can be set using <property name="eclipselink.logging.level" value="FINEST"/>

Best Regards,
Chris

[Updated on: Fri, 03 August 2012 15:43]

Report message to a moderator

Re: @OneToMany Annotation problem [message #900064 is a reply to message #899863] Fri, 03 August 2012 18:15 Go to previous messageGo to next message
Lars Drießnack is currently offline Lars DrießnackFriend
Messages: 9
Registered: August 2012
Junior Member
Hi,

thank you for your answer.

What do you mean with fields and properties? All annotations are directly on the private variable of the class or on the class itself (like @Entity), nothing on getters or somewhere else.

This is the log when loading a team which should have 2 players:
[EL Finer]: client released
[EL Finer]: client acquired: 1688731466
[EL Finer]: acquire unit of work: 1365870310
[EL Finest]: Execute query ReadObjectQuery(name="readObject" referenceClass=Team sql="SELECT ID, COUNTRY, INSERTEDAT, INSERTEDBY, NAME, TOURNAMENT_ID FROM MYT_Team WHERE (ID = ?)")
[EL Finest]: Register the existing object de.ld.mytournament.domain.entity.team.Team@4f77d12e
[EL Finest]: Register the existing object de.ld.mytournament.domain.entity.tournament.Tournament@55c2a210
[EL Finest]: Register the existing object de.ld.mytournament.domain.entity.tournament.TournamentProperties@cd76ae54


As you can see the framework shows that team, tournament and tournamentproperties entities are loaded but no player entities.

I tried to analise the log, the only thing i found was this error, but this should be no problem (msg is written for lots of tables while creating the database):
[EL Finest]: Connection(30136561)--Connection acquired from connection pool [default].
[EL Fine]: Connection(30136561)--ALTER TABLE MYT_Player DROP CONSTRAINT FK_MYT_Player_TEAM_ID
[EL Fine]: SELECT 1 FROM DUAL
[EL Finest]: Connection(30136561)--Connection released to connection pool [default].
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-00942: Tabelle oder View nicht vorhanden

Error Code: 942
Call: ALTER TABLE MYT_Player DROP CONSTRAINT FK_MYT_Player_TEAM_ID
Query: DataModifyQuery(sql="ALTER TABLE MYT_Player DROP CONSTRAINT FK_MYT_Player_TEAM_ID")



regards
Re: @OneToMany Annotation problem [message #900777 is a reply to message #900064] Wed, 08 August 2012 13:01 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

When you create your objects you must set both sides of the relationship. You are most likely only setting the ManyToOne and not adding to the OneToMany, you have to do both, otherwise your objects are out of synch. Because EclipseLink maintains a shared cache, you get back what you inserted, so get the same out of synch data. You should fix your code, but you could also disable caching, or refresh the object.



James : Wiki : Book : Blog : Twitter
Re: @OneToMany Annotation problem [message #903036 is a reply to message #899863] Tue, 21 August 2012 17:41 Go to previous message
Lars Drießnack is currently offline Lars DrießnackFriend
Messages: 9
Registered: August 2012
Junior Member
ok, that helped. Thank you.
Previous Topic:Noob Problem: ClientSession.getAccessors() returns null
Next Topic:Problem in using SQL Keyword in JPQL
Goto Forum:
  


Current Time: Tue Apr 16 14:10:34 GMT 2024

Powered by FUDForum. Page generated in 0.02546 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top