title: Kotlin with JPA/Hibernate: no lazy-loading without `open`?
body: <p>Most Kotlin JPA example code looks like this</p>
  
  <pre><code>class Person(val name: String, val age: Int) { /* ... */ }
  </code></pre>
  
  <p>or even</p>
  
  <pre><code>data class Person(val name: String="", val age: Int=0) { /* ... */ }
  </code></pre>
  
  <p>Now, the <a href="https://docs.jboss.org/hibernate/orm/5.1/userguide/html_single/Hibernate_User_Guide.html#entity-pojo" rel="noreferrer">Hibernate User Guide</a>, and I think also several other ORMs, state that they usually want to create proxies or otherwise extend the model class, but to allow that in Kotlin the class has to be explicitly defined <code>open</code>. This is currently impossible with data classes and I assume, judging from my own experience, that most people don't think about it when writing JPA entities in Kotlin.</p>
  
  <p>So, to come to my question (this is stackoverflow after all), is it enough to do</p>
  
  <pre><code> open class Person(val name: String, val age: Int) { /* ... */ }
  </code></pre>
  
  <p>or would we actually have to do</p>
  
  <pre><code> open class Person(open val name: String, open val age: Int) { /* ... */ }
  </code></pre>
  
  <p>to not needlessly hinder the ORM at doing its job properly?<br>
  If it really is harmful, we should probably propose to add a warning to IntelliJ IDEA, that if a class is has an <code>@Entity</code> annotation, it should be defined <code>open</code>.</p>