How do I stop writing Java property definition tools for BlazeDS & JPA that I don't want?

BlazeDS will not serialize a property unless it has both a receiver and a setter. However, many of my Java properties are read-only. So now I have to add setters to support the Unmarshalling process. If any of the users of these domain objects starts calling these setters on their own, it will break the semantics of the value-object of these things and will probably cause all kinds of system problems.

I had to do a lot in the past to support some aspects of JPA and never liked it. This is because we add JPA annotations to properties and not to private fields (to avoid another problem).

Besides using Javadoc to warn yourself and others, what does a programmer do?

Edit: I have to add that these additional setters are NOT part of the open interface that these objects implement .... but they are still there nonetheless.

+3
source share
2 answers

You have several options: use your own serialization engine or use BlazeDS version 4. I wrote a short article related to this, maybe it can help you. Link http://cornelcreanga.com/2009/09/blazeds-amf-and-read-only-properties/ .

+1
source

@Access. , , . , , :

private String firstName;

@Access(AccessType.PROPERTY) 
@Column(name="FIRST_NAME")
protected String getFirstNameForDatabase() {
    return "Mr. " + this.firstName;
}

"FIELD", , "" . 'dummy' /, , JPA, . , .

+2

Source: https://habr.com/ru/post/1778823/


All Articles