I'm using the latest version of Hibernate with Java. I've got three enum types that are being used as property names, each of the three property names go with different objects. There are different sets of property names for each object. Each property name is stored in a map with it's respective property value object, the property value object also stores it's own property name. The issue is that Hibernate can't figure out which of the 3 enum types the interface is, and thus can neither save the enum type nor re-construct it.
I've read the documentation around proxy object and Hibernate Interceptors, my initial plan was to create a -fourth- enum which would identify which of the three other enum types the hibernate enum was and then check that in the 'Interceptor' step outlined here: https://www.hibernate.org/339.html. Unfortunately I wouldn't have the property values until hibernate assigned them, after it needs the proxy object.
Is my best bet to cache all the 'sets' performed by Hibernate until it assigns the 'type' enum, then use the proper enum type from then on forward -in the proxy-?
Code examples per request:
public interface PropertyEnum {
public List<ClientPropertyName> getPropertyNames();
public List<String> getWorkflowNames();
public List<String> getManagerNames();
public boolean hasMultipleFields();
public boolean hasFieldHeader();
public String getFieldHeader();
public int fieldCount() ;
public PropertyDAO getComparatorDAO();
public PropertyWidgetDAO getWidget();
public boolean hasDisplayLocation();
public DisplayLocation getDisplayLocation();
public int compareTo(PropertyEnum propertyEnum);
}
/********************************************************/
public enum PropertyType1 implements Serializable,PropertyEnum{
etc,
etc1,
etc2;
public List<ClientPropertyName> getPropertyNames();
public List<String> getWorkflowNames();
public List<String> getManagerNames();
public boolean hasMultipleFields();
public boolean hasFieldHeader();
public String getFieldHeader();
public int fieldCount() ;
public PropertyDAO getComparatorDAO();
public PropertyWidgetDAO getWidget();
public boolean hasDisplayLocation();
public DisplayLocation getDisplayLocation();
public int compareTo(PropertyEnum propertyEnum);
}
/********************************************************/
public enum PropertyType2 implements Serializable,PropertyEnum{
etc,
etc1,
etc2;
public List<ClientPropertyName> getPropertyNames();
public List<String> getWorkflowNames();
public List<String> getManagerNames();
public boolean hasMultipleFields();
public boolean hasFieldHeader();
public String getFieldHeader();
public int fieldCount() ;
public PropertyDAO getComparatorDAO();
public PropertyWidgetDAO getWidget();
public boolean hasDisplayLocation();
public DisplayLocation getDisplayLocation();
public int compareTo(PropertyEnum propertyEnum);
}
/********************************************************/
@Entity
@Proxy(lazy=false)
@Table(name="Properties")
@GenericGenerator(name = "gg1", strategy = "increment")
public class Property implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private boolean hibFinal = true;
private List<PropertyValue> props = new ArrayList<PropertyValue>();
private PropertyData data = new PropertyData();
public Property(PropertyEnum property, List<List<String>> value2) {
this.setName(property);
this.setValuesPF(value2);
this.hibFinal = true;
}
public Property(PropertyEnum property, String value2) {
this.setName(property);
this.setValue(value2);
this.hibFinal = true;
}
public Property(){
//assume hibernate is constructing.
this.hibFinal=false;
}
private void finalizeHibernate()
private boolean hasValues()
@Transient
public PropertyData getDAO()
@Transient
public boolean hasMultiple()
@Transient
public String getValue()
@OneToMany(fetch = FetchType.EAGER)
@Cascade({CascadeType.DELETE_ORPHAN,CascadeType.ALL})
@Fetch(value = FetchMode.SUBSELECT)
public List<PropertyValue> getValues()
public void setValues(List<PropertyValue> v)
public void setValuesPF(List<List<String>> v)
public void setValue(String v)
@Enumerated(EnumType.STRING)
/* I had two marked up objects for each enum, then I switched to interface.
* Hibernate cannot tell this interface is an enum, and is not smart enough
* to know to store the enum object name as a seperate column so it can
* properly instantiate it.
*/
public PropertyEnum getName() {return data.getName();}
public void setName(PropertyEnum n){this.data.setName(n);}
@Id @GeneratedValue(strategy=GenerationType.AUTO)
public Integer getId() {
return this.data.getId();
}
public void setId(Integer id) {
this.data.setId(id);
}
}