@OneToMany Annotation problem [message #899863] |
Thu, 02 August 2012 12:17  |
Eclipse User |
|
|
|
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 #900064 is a reply to message #899863] |
Fri, 03 August 2012 14:15   |
Eclipse User |
|
|
|
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06902 seconds