I'm getting this Hibernate error:
org.hibernate.MappingException: Could not determine type for:
a.b.c.Results$BusinessDate, for columns: [org.hibernate.mapping.Column(businessDate)]
The class is below. Does anyone know why I'm getting this error??
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"businessDate"
})
@XmlRootElement(name = "Results")
@Entity(name = "Results")
@Table(name = "RESULT")
@Inheritance(strategy = InheritanceType.JOINED)
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class Results implements Equals, HashCode
{
@XmlElement(name = "BusinessDate", required = true)
protected Results.BusinessDate businessDate;
public Results.BusinessDate getBusinessDate() {
return businessDate;
}
public void setBusinessDate(Results.BusinessDate value) {
this.businessDate = value;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"raw",
"display"
})
@Entity(name = "Results$BusinessDate")
@Table(name = "BUSINESSDATE")
@Inheritance(strategy = InheritanceType.JOINED)
public static class BusinessDate implements Equals, HashCode
{
....
Update: This code was generated by HyperJaxB. So I don't claim to understand it all, just trying to make some changes to it!
Update2: Here's the full (yah it's big) src file
Using a static nested class as a field type is fine and supported. But Hibernate won't know how to map such a complex type to a column type (which is what the error message says).
So you'll need either to create a user type to handle this or to annotate the Results.BusinessDate
field with a @OneToOne
annotation to persist it in another table (I would also remove the @Inheritance
which is useless but this is not the problem here).
Update: Just to clarify, using a user type or mapping the complex type with @OneToOne
does work. The following code works perfectly (tested):
@Entity
public class EntityWithStaticNestedClass implements Serializable {
@Id
@GeneratedValue
private Long id;
@OneToOne
private EntityWithStaticNestedClass.StaticNestedClass nested;
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public EntityWithStaticNestedClass.StaticNestedClass getNested() {
return nested;
}
public void setNested(EntityWithStaticNestedClass.StaticNestedClass nested) {
this.nested = nested;
}
@Entity
public static class StaticNestedClass implements Serializable {
@Id
@GeneratedValue
private Long id;
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
}
}
And both entities get well persisted in their respective tables. But you're not showing the entire code nor the exact error so I can't say why it didn't for you (maybe you're missing @Id
etc).
That being said, if you don't want businessDate
to be persisted at all, annotate it with @Transient
(with JPA, fields are persistent by default):
Update: You can't mix field and property access. So you need to annotate getBusinessDate()
with @Transient
here. Sorry, I couldn't guess that from the shown code and I thought it would be obvious.