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

Use JPA's @Transient ist not visible in OData metadata #76

Open samakovuluk opened 5 years ago

samakovuluk commented 5 years ago

Just created my first JPA entity together with Olingo + JPA Processor. I want to use an entity property with the @Transient annotation so the database is not populated with that value. Unfortunately, that property is not visible in the $metadata of the service. Is there any way to create a visible property that is transient for JPA?

wog48 commented 5 years ago

At the moment transient fields are not supported. Many reason for this is the question how to fill them during GET request: The JPA Processor converts OData GET requests into JPA Tuple Queries to have a nice way to handle $select and to convert the result. A consequence of this is that a hook would be needed for transient fields, which is called after the query has finished. Can you provide an example how you would like to fill the transient field?

samakovuluk commented 5 years ago

This is an example of how I tried to use @Transient

    @Column(name = "description")
    private String text;
//getter setter
    @Column
    @Transient
    private List<String> words;

    public List<String> getWords() {
        return Arrays.asList(text.split(" ,"));
    }

    public void setWord(List<String> words) {
        this.words = words;
    }
wog48 commented 5 years ago

In general this is a doable thing, but more complicated as it looks at the first glance.

  1. As mentioned the JPA Processor generates tuple queries, so no instances of the Entity are created and the code that creates the transient values has to be in a hook
  2. In your case a collection property needs to be generated without having the @Collection annotation, which is used as trigger up to now
  3. Additional metadata are required to handle requests that only selects the transient field, but not the persistent it based on, so the later one can be retrieved from the database and provided to the hook

I have to it on the requirements list

voronczoff commented 5 years ago

Any luck with actually achieving it?

samakovuluk commented 3 years ago

Do have you have some improvements with that issue?