title: "Not known whether passed class name ... is safe" using JPA EmbeddedId with Hibernate
body: <p>In an very distilled version of the sample code available from a tutorial, <a href="http://www.java2s.com/Tutorial/Java/0355__JPA/EmbeddedCompoundPrimaryKey.htm" rel="noreferrer">Embedded Compound Primary Key : Primary Key « JPA « Java Tutorial</a>, I'm getting:</p>
  
  <pre class="lang-none prettyprint-override"><code>javax.persistence.PersistenceException: [PersistenceUnit: unit] Unable to build Hibernate SessionFactory
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:877)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:805)
      at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
      at [my code that calls e.persist on a Student]
  </code></pre>
  
  <p>The exception is fairly generic, but Hibernate provides some good log debug info (I've replaced the actual package name with &lt;package&gt;):</p>
  
  <pre class="lang-none prettyprint-override"><code>[DEBUG] org.hibernate.boot.internal.ClassLoaderAccessImpl: Not known whether passed class name [&lt;package&gt;.Student] is safe
  [DEBUG] org.hibernate.boot.internal.ClassLoaderAccessImpl: No temp ClassLoader provided; using live ClassLoader for loading potentially unsafe class : &lt;package&gt;.Student
  </code></pre>
  
  <p>Here's the distilled code.  (The backstory is that I'd been trying, to no avail, to create an entity with an embedded id.  After a while of trying to debug that, I re-started with this tutorial code, removing things until I got the same error.)</p>
  
  <pre><code>@Embeddable
  class StudentId {
      private int id; 
  
      public StudentId() {}
  
      public StudentId(int id) { this.id = id; }
  
      @Override
      public boolean equals(Object o) { 
          return ((o instanceof StudentId) &amp;&amp; id == ((StudentId) o).id);
      }
  
      @Override
      public int hashCode() { return id; }
  }
  </code></pre>
  
  <p></p>
  
  <pre><code>@Entity
  public class Student {
      @EmbeddedId
      private StudentId id;
  
      public Student() {}
  
      public Student(int id) { this.id = new StudentId(id); }
  }
  </code></pre>