Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jpa-dev] Java Records Alignment?
  • From: Xavier Dury <kalgon@xxxxxxxxxxx>
  • Date: Wed, 13 May 2020 09:31:59 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ao87RpUcdWCR/UTa0tEumvie3F3ugd6IesydUVIGiQQ=; b=FL7ZwBIl68Ra0mScLmdVkFM/qdmltlzDa7wOkOkZQtfaDIdy49MXCcmNu9qGBTV9MFI9StoM+Q/mbZQA+31d5C/p4HJXfKyaeJOJD47W4waE+/Tx4D/r+vM5JcRJaPQItIuzLsMzvQJKzLAZo8dVqjZU8BpOAQx6cE0gzP4IggBZyjTWLyyO5kIAuP5Vel+6Krn/FDlLXz1WJMUzN09+vZBa156ovA14nR5fL8NRaxfw0XUuegKA9mW8WObs4uhTfmm2wH31krHNSIH+pYj8EX+JxN1I2/PPGuIecCBk1hM5GqlEq7yBPoaOAx3LhhheTCOSgkSLxW5dG5QPIrUezA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N4li4jWQ0TX/7GaR4N+67tTYKPSS6EI71vYbSoUQSNZrh2tupB8iIa83EEZmPFT0YRfFohw7vA9krAqIV55kyMm2llEgtpKNZBbrZryMMAOcSMsYFww7u7Yqub+VXZu9eGe0JAoEByYiD4xoUFvqstPvGBuHHykvAmgT0T0nYeSsinyXektVO0IIofBVEac4iJqdWqmQJlKJoAfm+Bne3gmgLDH6RmMtHaYMiUsLVH1BonGJmNG6/iD7/VnTXtarfVWrGacVx7wBCBz5Ylp6G00+Fws5LIW5OaCHwHF1ccTKrnP6Tb/i/kUs6lD3m8yLJzjaC3xR95IKQxEc+BHgRQ==
  • Delivered-to: jpa-dev@xxxxxxxxxxx
  • List-archive: <https://www.eclipse.org/mailman/private/jpa-dev>
  • List-help: <mailto:jpa-dev-request@eclipse.org?subject=help>
  • List-subscribe: <https://www.eclipse.org/mailman/listinfo/jpa-dev>, <mailto:jpa-dev-request@eclipse.org?subject=subscribe>
  • List-unsubscribe: <https://www.eclipse.org/mailman/options/jpa-dev>, <mailto:jpa-dev-request@eclipse.org?subject=unsubscribe>
  • Thread-index: AQHWFa4ZbG5+kka1oUmQQVzu4CbeQKiFx2+AgAH/jICAAJaRgIAAA/+AgABdfi+AACOtgIAGH7oAgAFau+mAEXFEAIAEGIzO
  • Thread-topic: [jpa-dev] Java Records Alignment?

Hi,

 

I made a small project to test the various use-cases which have been discussed in this thread.

 

https://github.com/kalgon/jpa-records

 

Let me know if you think some thing should be added/changed.

 

Regards,

Xavier

 

From: reza_rahman
Sent: Sunday, May 10, 2020 20:58
To: jpa developer discussions
Subject: Re: [jpa-dev] Java Records Alignment?

 

Do you think you still have an interest to do this? If not, I could see if other folks in the community would be interested. I think a well done analysis of this would be a solid contribution to JPA.

 

Reza Rahman

Jakarta EE Ambassador, Author, Blogger, Speaker

 

Please note views expressed here are my own as an individual community member and do not reflect the views of my employer.

 

Sent via the Samsung Galaxy S7, an AT&T 4G LTE smartphone

 

 

-------- Original message --------

From: Xavier Dury <kalgon@xxxxxxxxxxx>

Date: 4/29/20 12:41 PM (GMT-05:00)

To: jpa developer discussions <jpa-dev@xxxxxxxxxxx>

Subject: Re: [jpa-dev] Java Records Alignment?

 

Hi,

 

Java records could also be used for (composite) identifiers (@EmbeddedId) where you *have* to implement hashCode() and equals().

 

When/if I can find some time, I’ll try to create some code examples for all the use-cases which have already been identified in this thread.

 

Regards,

Xavier

 

From: Aleksander Nowak
Sent: Tuesday, April 28, 2020 21:55
To: jpa-dev@xxxxxxxxxxx
Subject: Re: [jpa-dev] Java Records Alignment?

 

Hi,

thanks for the article. But there is more hassle with Java records. Java records will automaticly implement hashCode() and equals() based on their attributes. And those implementations may not be suitable for your needs. So you will propably have to override them and this will lead to more effords to get them work properly.

But i like the idea with immutable entities.

Greetings

Aleksander Nowak

 

Am 25.04.2020 um 00:23 schrieb Markus Stauffer:

Hi

Have a look at the following blog post: https://vladmihalcea.com/java-records-jpa-hibernate/#more-18690

In my opinion the definition of the Entity Class (JPA Spec - Chapter 2.1) should be updated. Some sort of immutable Entity Class could be introduced for java records.

cheers
--
Markus Stauffer

On 24.04.20 22:17, Xavier Dury wrote:

Hi,

 

Off the top of my head, I would see Records being used for two main purposes: DTO/projections and attributes.

 

For DTO/projections, I don't think there is much to do as JPA already allows returning objects in queries with the syntax "select new my.company.MyDTO(e.attribute, e.anotherAttribute) from MyEntity e". I don't think Records behave so much differently than regular classes that they would need special treatment.

 

For attributes, I think it's a bit more complicated as there are 2 different cases depending on where you would put the mapping information.

 

If you have access to the Record source code, you could annotate the Records components with @Column, @Basic, etc. as components accept annotations which target fields.

 

If you don't have access to the source code (or if you want to keep mapping separated from the code), you could declare the mapping in orm.xml as Records could be considered as a kind of immutable embeddable objects (and it's already possible to declare embeddable mappings in orm.xml).

 

Anyway, the JPA provider would need to detect that the object is a Record and construct it appropriately (Record constructor for Records vs. default constructor + setters for regular embeddables).

 

Everything should still work when nesting Records and mixing regular embeddables with Records.

 

There is always the possibility to use AttributeConverters for single-column Records. For now, AttributeConverters can't be used for multi-columns objects and you need to resort to vendor-specific adapters. This is a limitation that should really be addressed in the next JPA version.

 

A third purpose for Record would be for immutable entities: entities which are fully constructed (including their id) from their constructor and never updated. Hibernate can already mark an entity as @Immutable which can improve performance as no dirty checking is needed for those entities.

 

Regards,

Xavier

 

From: sankarraman.vedagiri@xxxxxxxxxxxxxx
Sent: Friday, April 24, 2020 16:42
To: 'jpa developer discussions'
Subject: Re: [jpa-dev] Java Records Alignment?

 

Hi Reza

 

       I think a scenario based PoC can be done and check the outcomes and make fixes if it doesn’t represent the data in a desired way. Generally in a business app, most of the times the Java Records will be as DTOs as you said.

 

Regards

 

Sankarraman V

 

 

Altius Digital

New 10/3 Old 18/3 Devanathan Colony

West Mambalam

Chennai

+ 91 9380458402

Email: Sankarraman.vedagiri@xxxxxxxxxxxxxx

 

From: jpa-dev-bounces@xxxxxxxxxxx <jpa-dev-bounces@xxxxxxxxxxx> On Behalf Of reza_rahman
Sent: 24 April 2020 19:57
To: jpa developer discussions <jpa-dev@xxxxxxxxxxx>
Subject: Re: [jpa-dev] Java Records Alignment?

 

Do you or anyone else want to work with me on an analysis from the end user standpoint?

 

I don't think this is that straightforward and will require some level of scenario outlining. In particular, it is still unclear to me how Java Records fit into an overall  application domain model vis-a-vis JPA entities and embeddables. It is possible the only use case for Java Records are as DTOs, in which case a possible set of enhancements could be just some relatively simple converters. There may even be space here for a vendor neutral small utility library and nothing in JPA itself (maybe part of DeltaSpike).

 

Reza Rahman

Jakarta EE Ambassador, Author, Blogger, Speaker

 

Please note views expressed here are my own as an individual community member and do not reflect the views of my employer.

 

Sent via the Samsung Galaxy S7, an AT&T 4G LTE smartphone

 

 

-------- Original message --------

Date: 4/24/20 1:29 AM (GMT-05:00)

To: jpa developer discussions <jpa-dev@xxxxxxxxxxx>

Subject: Re: [jpa-dev] Java Records Alignment?

 

Hi,

 

Aren't single-valued records somehow already supported by writing custom AttributeConverters?

 

For multi-valued records, a enhancement proposal for AttributeConverters exists: 

 

Regards,

Xavier

 

On 23 Apr 2020 12:57 a.m., Lukas Jungmann <lukas.jungmann@xxxxxxxxxx> wrote:

Hi,

On 4/18/20 8:20 PM, reza_rahman wrote:
> Lukas,
>
> I just wanted to quickly ask - is it sensible to file an issue on Java
> Records alignment with JPA?

Yes, it is, feel free to go ahead with that.

thanks,
--lukas

  If it is, I will see if someone else from
> the community can research this and file a preliminary issue. My IP
> chain with Microsoft and Jakarta EE is still murky, so it is best I
> don't enter too many details too frivolously myself.
>
> Reza Rahman
> Jakarta EE Ambassador, Author, Blogger, Speaker
>
> Please note views expressed here are my own as an individual community
> member and do not reflect the views of my employer.
>
> _______________________________________________
> jpa-dev mailing list
> jpa-dev@xxxxxxxxxxx
> To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jpa-dev
>
_______________________________________________
jpa-dev mailing list
jpa-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jpa-dev

 

 




_______________________________________________
jpa-dev mailing list
jpa-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jpa-dev




_______________________________________________
jpa-dev mailing list
jpa-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jpa-dev

 

 


Back to the top