tlegrand
tlegrand

Reputation: 806

Empty collection returned with Spring JPA

I am using JPA with Spring to retrieve a list of "Feature" from a "Role". But, when I want to retrieve this list from my application, it returns me an empty list whereas I retrieve something when I execute the generated SQL request from a SQL client

Here is my data model:

FEATURE: - id (PK) - name - description

AD_ROLE: - id (PK) - name

FEATURE_AD_ROLE - feature_id (FK to FEATURE.id) - ad_role_id (FK to AD_ROLE.id)

My entities are:

@Entity
@Table(name = "FEATURE")
public class Feature implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    private int id;

    private String name;
    private String description;

    @ManyToMany
    @JoinTable(name = "FEATURE_AD_ROLE", joinColumns = @JoinColumn(name = "FEATURE_ID", referencedColumnName = "ID"), inverseJoinColumns = @JoinColumn(name = "AD_ROLE_ID", referencedColumnName = "ID"))
    private Collection<ADRole> adRoles;

    // getter/setters
}


@Entity
@Table(name = "AD_ROLE")
public class ADRole implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    private int id;

    private String name;

    @ManyToMany(mappedBy = "adRoles")
    private List<Feature> features;

    // getters/setters
}

My DAO:

@Repository
public interface FeatureDao extends JpaRepository<Feature, Long> {

    @Query("SELECT f FROM Feature f JOIN f.adRoles fa WHERE fa.name = :adProfile")
    public Collection<Feature> getFeaturesByADProfile(@Param("adProfile") String adProfile);

}

This generates this SQL request:

select feature0_.id as id1_1_, feature0_.description as description2_1_, feature0_.name as name3_1_ from FEATURE feature0_ inner join FEATURE_AD_ROLE adroles1_ on feature0_.id=adroles1_.FEATURE_ID inner join AD_ROLE adrole2_ on adroles1_.AD_ROLE_ID=adrole2_.id where adrole2_.name=?

When I execute this request from a SQL client, I can see a result.

My DBMS is Oracle.

Can you help me, please?

Upvotes: 1

Views: 572

Answers (1)

tlegrand
tlegrand

Reputation: 806

Actually, never mind. This morning, I found out that it was because I added entries from my SQL client and I did not commit the transaction. :(

This is just... awkward.

Upvotes: 1

Related Questions