eclipse / jnosql

Eclipse JNoSQL is a framework which has the goal to help Java developers to create Jakarta EE applications with NoSQL.
Other
229 stars 72 forks source link

Alignment with jakarta.persistence API: @Column can be optional #392

Open georgleber opened 1 year ago

georgleber commented 1 year ago

Which JNoSQL project the issue refers to?

JNoSQL (Core)

Use case

Coming from an JPA / relational background it was a little counterintuitive that the @Column is mandatory for every field that should be included in the document. Especially for complex relations, that are annotated with @Entity or @Embeddable.

@Entity public class Book {
    @Id  private String id;
    @Column  private String title;
    private Author author; // is not added to document because of missing @Column annotation
}

@Entity
public class Author {
    @Column private String name;
}

Feature proposal

Make @Column optional and mark fields that should be not persisted in the resulting document with @Transient and/or respect the transient keyword.

dearrudam commented 1 year ago

Thanks, @GeorgHenkel for this contribution!

This behavior involves not just only the JNoSQL project but the Jakarta NoSQL specification itself. Maybe it's interesting to address this issue in Jakarta NoSQL specification. What do you think @otaviojava?

otaviojava commented 1 year ago

It is a considerable discussion and requires debates like this.

As with any topic, we are talking about trade-offs.

While the proposal to eliminate the need for the @Column annotation in the Eclipse JNoSQL framework may seem appealing in simplifying the codebase and convention over configuration, it poses several significant drawbacks that outweigh its potential benefits.

Based on trade-offs, we can define it. One thing we can do is allow the vendor to make this column Optional or not.

georgleber commented 1 year ago

I completely get your points and mostly agree with you that explicit annotations are a better way of documentation and clarity for developers unfamiliar with the codebase. I would definitively go with the current solution of explicit annotations. But I wanted to mentioned it, because with a JPA background I was used to drop the annotations where it is not needed :)

One thing we can do is allow the vendor to make this column Optional or not

When I understand you correct, the vendor can decide, if @Column must be set explicitly or not? In that case I see the need for a new explicit annotation @Transient to make clear, when a field should not be stored. Because if the column is optional, you cannot make transient fields visible except with the Java keyword or an explicit annotation.

otaviojava commented 1 year ago

But I wanted to mentioned it, because with a JPA background I was used to drop the annotations where it is not needed :)

And this point is super important; thank you for raising it.

When I understand you correct, the vendor can decide, if @Column must be set explicitly or not?

It works with explicit annotations, but we can decide to be optional such as JPA or delegates it to the vendors.