SAP / olingo-jpa-processor-v4

The JPA Processor fills the gap between Olingo V4 and the database, by providing a mapping between JPA metadata and OData metadata, generating queries and supporting the entity manipulations.
Apache License 2.0
122 stars 76 forks source link

expand fail for v2.0.0 #236

Closed mbossX closed 7 months ago

mbossX commented 8 months ago
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Role implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(length = 32, nullable = false)
    private String name;

    @Column(length = 128)
    private String comment;

    @Column(columnDefinition = "text")
    private String permissions;

    @OneToMany(mappedBy = "role")
    private List<User> users;
}

@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(length = 32)
    private String name;

    private String email;

    @Column(length = 11, unique = true, nullable = false)
    private String username;

    @Column(length = 16, nullable = false)
    private String password;

    @Column(nullable = false, columnDefinition = "tinyint DEFAULT 0")
    private Integer status;

    @Column(name = "role_id")
    private Integer roleId;
    // @EdmIgnore
    // @Column(name = "role_id", precision = 10, insertable = false, updatable = false)
    // private Integer roleId;

    @ManyToOne
    @JoinColumn(name = "role_id", referencedColumnName = "id", insertable = false, updatable = false)
    private Role role;
}

when browser http://localhost:8081/odata/v1/Users(1)?$expand=role
return
Could not determine recommended JdbcType for tech.jiyun.odata.entity.Role use v2.0.0 and springboot 3.1.5

but same code work fine at v1.1.1 and springboot 2.7.17

mbossX commented 8 months ago

@wog48 plase check this.

mbossX commented 8 months ago

spring-boot version is 3.1.5 dependencies show below:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.33</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.sap.olingo</groupId>
            <artifactId>odata-jpa-processor</artifactId>
            <version>2.0.0</version>
        </dependency>
    </dependencies>
mbossX commented 8 months ago

crash at
com.sap.olingo.jpa.processor.core.query.JPAAbstractJoinQuery.java:642 createFromClauseNavigationJoins()

this.target = (From)this.target.as(cast.getTypeClass());

cast.getTypeClass() return "tech.jiyun.odata.entity.Role" but this.target.as crash
mbossX commented 8 months ago

https://github.com/mbossX/ojp-issue-236

minimal test repo

kumarvika commented 8 months ago

Hi @mbossX, I am also facing the issue, but for me, the below line is at 747 in the same class and method.

target = (From<?, ?>) target.as(cast.getTypeClass());

Please do let me know if you find any solution. Thanks

mbossX commented 8 months ago

temporarily downgrade to version 1.1.1 and springboot 2.7.17.

kumarvika commented 8 months ago

Thanks, @mbossX, We are upgrading to implement Java 17 and Spring Boot 3. Thanks anyway.

vijaykumaroutlook commented 8 months ago

i am facing this issue with spring boot 3.1.5.

Vislesha commented 8 months ago

Dear Team: We are also facing the same issue with Expand! We have recently migrated all our APIs from Spring 2.7 to Spring3.1.5. Our previous version has heavy dependence on OData library for all our dashboards and dynamic data explorations with expand and aggregations. Deeply appreciate if someone can address this ASAP or at least provide an ETA so that we can plan our deliverables. TIA, ATTN: (@wog48 )

DimitarTanev87 commented 8 months ago

I am facing similar issue with spring boot 3.

@Table(name = "workflow") class Activity { .... @OneToMany(mappedBy = "workflow", orphanRemoval = true, cascade = CascadeType.ALL) private List logs; ..... }

@Table(name = "workflow_log") class ActivityLog { .... @ManyToOne @JoinColumn(name = "workflow_id") private Activity workflow; ....

}

When execute ..../Activities?$top=2&$expand=Logs, I receive an error "The attribute [workflow_id] is not present in the managed type"

wog48 commented 8 months ago

This is the same issue as described in issue#238. As explained there, this is seen as an issue of the Hibernate version comming with Spring Boot 3.x. You can try to use the JPA Processor own JPA Criteria Builder implementation odata-jpa-processor-cb by adding the corresonding dependency to you pom.

vijaykumaroutlook commented 7 months ago

Any one able to find a solution for this issue?

wog48 commented 7 months ago

It turned out that there is also a problem in the JPA Processor

wog48 commented 7 months ago

Please have a look at version 2.0.2.In case you still face the problem, reopen the issue