Is it possible to create a class in Java to access with hibernate a database table with primary key compound (two or more fields), whose attributes with the @Column
are of type StringProperty
or DoubleProperty
of JavaFX?
A simple example of what I'm asking:
PersonPK Class
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
@Embeddable
public class PersonPK implements Serializable{
private static final long serialVersionUID = 1L;
private StringProperty firstname;
private StringProperty lastname;
public PersonPK(){
this.firstname= new SimpleStringProperty();
this.lastname = new SimpleStringProperty();
}
public StringProperty firstnameProperty() {
return firstname;
}
@Column(name = "FIRSTNAME")
public String getfirstname(){
return this.firstname.get();
}
public void setFirstname(String firstname) {
this.firstname.set(firstname);
}
public StringProperty lastnameProperty() {
return lastname;
}
@Column(name = "LASTNAME")
public String getLastname(){
return this.lastname.get();
}
public void setLastname(String lastname) {
this.lastname.set(lastname);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((firstname == null) ? 0 : firstname.get().hashCode());
result = prime * result + ((lastname == null) ? 0 : lastname.get().hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PersonPK other = (PersonPK) obj;
if (firstname == null) {
if (other.firstname != null)
return false;
} else if (!firstname.get().equals(other.firstname.get()))
return false;
if (lastname == null) {
if (other.lastname != null)
return false;
} else if (!lastname.get().equals(other.lastname.get()))
return false;
return true;
}
}
Class Person
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;
import javafx.beans.property.StringProperty;
@Entity
@Table(name = "PERSON")
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
PersonPK personPK;
StringProperty comentario;
public Person(){
this.personPK=new PersonPK();
}
public PersonPK getPersonPK(){
return this.personPK;
}
public void setPersonPK(PersonPK personPK){
this.personPK=personPK;
}
@Column(name="COMMENTARY")
public String getComentario(){
return this.comentario.get();
}
public StringProperty comentarioProperty() {
return comentario;
}
public void setComentario(String comentario) {
this.comentario.set(comentario);
}
}
The error I get is the following:
Caused by: org.hibernate.MappingException: Could not determine type for: javafx.beans.property.StringProperty, at table: PERSON, for columns: [org.hibernate.mapping.Column (comment)] at org.hibernate.mapping.SimpleValue.getType (SimpleValue.java:455) at org.hibernate.mapping.SimpleValue.isValid (SimpleValue.java:422) at org.hibernate.mapping.Property.isValid (Property.java:226) at org.hibernate.mapping.PersistentClass.validate (PersistentClass.java:595) at org.hibernate.mapping.RootClass.validate (RootClass.java:265) at org.hibernate.boot.internal.MetadataImpl.validate (MetadataImpl.java:329) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build (SessionFactoryBuilderImpl.java:492) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build (EntityManagerFactoryBuilderImpl.java:878) ... 26 more