These are chat archives for hibernate/hibernate-orm

11th
Nov 2016
Knut Schleßelmann
@kschlesselmann
Nov 11 2016 10:24

Hi there! Currently I'm trying to create a more advanced model that's mapped to hibernate. Right now I end up with

org.hibernate.PropertyNotFoundException: Could not locate setter method for property [my.app.property.PropertyValue#value

I don't want to add a setter there because PropertyValue should be a value object (thus immutable). Any suggestions?

Steve Ebersole
@sebersole
Nov 11 2016 11:34
@DhyanandraSingh there is currently no support for schema tools against multi-tenant back ends
@jjoinme Not enough info
@kschlesselmann define the attribute AccessType as field rather than property
Knut Schleßelmann
@kschlesselmann
Nov 11 2016 11:36

@sebersole Currently I solved it using

@Embeddable
class PropertyValue {

    @Getter
    @Setter(value = AccessLevel.PRIVATE)
    private String value;

    PropertyValue(String value) {
        this.value = value;
    }

    protected PropertyValue() {
        this(null);
    }
}

what would your solution look like?

Steve Ebersole
@sebersole
Nov 11 2016 11:37
I have no idea what @Getter and @Setter are. those are not Hibernate nor JPA annotations
Knut Schleßelmann
@kschlesselmann
Nov 11 2016 11:38
@sebersole Nope, Lombok (basically they generate getter and setter ;-))
Steve Ebersole
@sebersole
Nov 11 2016 11:38
the setter being private btw is not an issue with HIbernate
it simply sets the private setter as accessible via reflection
no dea what affect Lombok has on that
JPA well defines AccessType
HIbernate follows that for the most part although allows things beyond JPA
in straight JPA the AccessType for an attribute on an Embeddable is defined by the context it is used
sounds like you are unfamiliar with AccessType, so I'd start researching there
so I said Hibernate does not care if the setter (nor getter for that matter) is private... it also does not care if there is a getter/setter - it can directly access field
those are the 2 basic AccessTypes which JPA defines
Steve Ebersole
@sebersole
Nov 11 2016 11:43
sounds like you have AccessType#PROPERTY in effect here
the easiest way is to add @Access(AccessType.FIELD) to your embeddable type definition
@Embeddable @Access(AccessType.FIELD) class PropertyValue { ... }
Knut Schleßelmann
@kschlesselmann
Nov 11 2016 11:47
@sebersole I use this PropertyValue in Property which is an @Embeddable which is used in an @ElementCollection in an @Entity. I'll try your suggestion.

@sebersole Nice, looks like

@Value
@Embeddable
@Access(AccessType.FIELD)
class PropertyValue {

    private String value;

    PropertyValue(String value) {
        this.value = value;
    }

    protected PropertyValue() {
        this(null);
    }
}

works as well :-)

Steve Ebersole
@sebersole
Nov 11 2016 11:49
the AccessType for that PropertyValue will be picked up from the @ElementCollection whihc in turn will be picked up from the @kschlesselmann Entity
but there are ways to control is more granularly (I showed you one)
etolbakov
@etolbakov
Nov 11 2016 15:02
@sebersole Thank you very much for response!
If to speak briefly when I select several entities with "integer []" field by criteria
the first record in result set has the array field equals to null while the data for this field exists in db.
I tried to describe the issue in details here. Please find the link below.
https://gist.github.com/etolbakov/57eb4d61475eb524f177c1f39b248bf2