Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Using a static nested class as a field type <strong>is fine</strong> 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 <code>Results.BusinessDate</code> field with a <code>@OneToOne</code> annotation to persist it in another table (I would also remove the <code>@Inheritance</code> which is useless but this is not the problem here).</p> <p><strong>Update:</strong> Just to clarify, using a user type or mapping the complex type with <code>@OneToOne</code> <strong>does work</strong>. The following code works perfectly (tested):</p> <pre><code>@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; } } } </code></pre> <p>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 <code>@Id</code> etc).</p> <p>That being said, if you don't want <code>businessDate</code> to be persisted at all, annotate it with <code>@Transient</code> (with JPA, fields are persistent by default):</p> <p><strong>Update:</strong> You can't mix field and property access. So you need to annotate <code>getBusinessDate()</code> with <code>@Transient</code>here. Sorry, I couldn't guess that from the shown code and I thought it would be obvious.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload