views:

72

answers:

2

I've set up a small project as a test. I'm using BlazeDS and JPA with Hibernate on my test server, and flex with with dpHibernate to access the Java entities. Each Java entity extends BaseEntity, a class that contains ID and UUID fields. The Flex entities are created by DTO2FX.

My problem is that, when I run the Flex project to try and display a few rows from a Users entity, the SQL that is actually being executed is joining every table in my database. This continues until I get java.lang.StackOverflowError. This behavior is completely unexpected, and I'm not really sure where to look to fix the problem. Any suggestions would be greatly appreciated.

Clearly I've left out some details, but I'm hoping this gives a reasonable idea about the project. I would be more than happy to include any code that might be helpful, but I really have no idea what's causing the behavior at the moment. Thanks!

EDIT: Here is a mapping that might better explain the problem.

@Entity
@FXClass(ignoreSuperclasses={Principal.class, UserDetails.class})
@Table(name="edrUser")
public class User extends BaseEntity implements IAbstractEntity, Principal, UserDetails {
    @Column(length=20)
    private String username;

    @ManyToMany(mappedBy="users",fetch=FetchType.LAZY)
    private Set<Department> departments = new HashSet<Department>(0);

    @ManyToOne
    @JoinColumn(name="company_id",nullable=false)
        private Company company;

    @OneToMany(cascade=CascadeType.ALL, mappedBy="user", fetch=FetchType.LAZY)
    private Set<DepartmentJobUserLink> departmentJobUsers = new HashSet<DepartmentJobUserLink>(0);

    @Column(length=20)
    private String password;

    @Column(length=20)
    private String forename;


    public User(){
        super();
    }

    /* Getters and setters */ 

}
+2  A: 

Did you force lazy-loading to false?

Thierry-Dimitri Roy
All of my entites are lazy-loading. I admit I'm inexperienced, but I thought that would keep anything from being loaded until it had to be.
Donny
Just wondering if I could get some clarification behind why lazy-loading should be false. I'm not sure I understand the reasoning behind your answer.
Donny
If you force lazy-loading to false and you load an object, then all properties are also loaded, which would result in a bunch of join sql statement. This is what seem to be the behavior that you describe.
Thierry-Dimitri Roy
That makes sense. In that case, then I have set lazy-loading to true.
Donny
A: 

Sounds to me like u having a cycle in your SQL tabledependencies, but thats just a guess. Checked that already?

ymene