2

I'm trying to add JavaFX BooleanPropety to my model which is persisted by Hibernate but I'm getting the following error.

Caused by: org.hibernate.MappingException: Could not determine type for: javafx.beans.property.BooleanProperty.

JavaFX StringProperty persisting just fine so I'm confused a little bit.

My model class is the following

@Entity
public class Currency {
    private String uuid;
    private BooleanProperty isDefault = new SimpleBooleanProperty();
    private StringProperty name = new SimpleStringProperty();
    private StringProperty code = new SimpleStringProperty();

    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid2")
    @Column(name = "id")
    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getName() {
        return name.get();
    }

    public void setName(String name) {
        this.name.set(name);
    }

    public String getCode() {
        return code.get();
    }

    public void setCode(String code) {
        this.code.set(code);
    }


    public boolean getIsDefault() {
        return isDefault.get();
    }

    public void setIsDefault(boolean isDefault) {
        this.isDefault.set(isDefault);
    }

    public StringProperty nameProperty() {
        return name;
    }

    public StringProperty codeProperty() {
        return code;
    }

    public BooleanProperty isDefaultProperty(){
        return isDefault;
    }
}
latsha
  • 1,298
  • 1
  • 14
  • 22

1 Answers1

6

Renaming

private BooleanProperty isDefault;

to

private BooleanProperty default;

solves the problem. The reason is that naming convention for boolean fields is quite different in java. That's explained in the following link

Community
  • 1
  • 1
latsha
  • 1,298
  • 1
  • 14
  • 22
  • I'm not quite sure why that works (though I have some guesses). I would recommend annotating the class with `@Access(AccessType.PROPERTY)`. This forces the ORM to call the get/set methods to access fields, instead of trying to access the fields via reflection. Have a look at [this blog](http://asipofjava.blogspot.com/2013/05/javafx-properties-in-jpa-entity-classes.html) and [this blog](http://www.marshall.edu/genomicjava/2014/05/09/one-bean-to-bind-them-all/) – James_D Jan 16 '15 at 13:07