| @OneToMany Annotation problem [message #899863] |
Thu, 02 August 2012 12:17  |
Lars Drießnack 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 09:41   |
Chris Delahunt Messages: 863 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 11:43] Report message to a moderator
|
|
|
| Re: @OneToMany Annotation problem [message #900064 is a reply to message #899863] |
Fri, 03 August 2012 14:15   |
Lars Drießnack 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 09:01   |
James Sutherland Messages: 1844 Registered: July 2009 |
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.01651 seconds