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 78 forks source link

fail at insert #233

Closed mbossX closed 10 months ago

mbossX commented 11 months ago

Entities like:

@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private String name;
    private Integer age;
    private String address;
    private String email;
    @EdmIgnore
    @Column(name = "role_id", precision = 10, insertable = false, updatable = false)
    private Integer roleId;
    @ManyToOne
    @JoinColumn(name = "role_id", referencedColumnName = "id")
    private Role role;
}

@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Role {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private String name;
    private String permissions;
    @OneToMany(mappedBy = "role")
    List<User> users;
}

when I insert new row url /api/odata/v1/Users with body {"name":"刘强12","address":"春熙路","age":16,"email":"aakk@172.com","role":{"id":1}} it fail and error is: Cannot invoke "java.util.Collection.add(Object)" because the return value of "java.lang.reflect.Method.invoke(Object, Object[])" is null Role {id: 1} exists in database(mysql) so what should I do?

version: 1.1.1

mbossX commented 11 months ago

@wog48

mbossX commented 11 months ago

if change Entity Role to:

@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Role {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private String name;
    private String permissions;
}

post request success and row inserted.

wog48 commented 11 months ago

Can you provide the call stack of the exception?

mbossX commented 11 months ago

use v2.0.0 and it worked. tks

mbossX commented 11 months ago

if u need more info, plase tell me. or close this issue.

wog48 commented 10 months ago

Thanks.