Hibernate MappingException Unknown entity: $Proxy2
- by slynn1324
I'm using Hibernate annotations and have a VERY basic data object:
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class State implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
private String stateCode;
private String stateFullName;
public String getStateCode() {
return stateCode;
}
public void setStateCode(String stateCode) {
this.stateCode = stateCode;
}
public String getStateFullName() {
return stateFullName;
}
public void setStateFullName(String stateFullName) {
this.stateFullName = stateFullName;
}
}
and am trying to run the following test case:
public void testCreateState(){
Session s = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction t = s.beginTransaction();
State state = new State();
state.setStateCode("NE");
state.setStateFullName("Nebraska");
s.save(s);
t.commit();
}
and get an
org.hibernate.MappingException: Unknown entity: $Proxy2
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:628)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1366)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
....
I haven't been able to find anything referencing the $Proxy part of the error - and am at a loss.. Any pointers to what I'm missing would be greatly appreciated.
hibernate.cfg.xml
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:hsql://localhost/xdb</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<property name="current_session_context_class">thread</property>
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<mapping class="com.test.domain.State"/>
in HibernateUtil.java
public static SessionFactory getSessionFactory(boolean testing ) {
if ( sessionFactory == null ){
try {
String configPath = HIBERNATE_CFG;
AnnotationConfiguration config = new AnnotationConfiguration();
config.configure(configPath);
sessionFactory = config.buildSessionFactory();
} catch (Exception e){
e.printStackTrace();
throw new ExceptionInInitializerError(e);
}
}
return sessionFactory;
}