Pessoal estou tendo problemas com o Hibernate 3.
se alguem souber ou já passou por isso?
codigo:
Configuration cfg = new Configuration();
SessionFactory sessionFactory = cfg.configure().buildSessionFactory();
session = sessionFactory.openSession();
Usuario user = (Usuario) session.load(Usuario.class,new Integer(1));
System.out.println(user.getNome());
no Usuario.hbm.xml esta assim:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class
name="br.com.maringa.eventosrel.Usuario"
table="usuario"
catalog=""
>
<id
name="Id"
type="java.lang.Integer"
unsaved-value="null"
>
<column name="id" length="11" not-null="true" sql-type="int" />
<generator class="native" />
</id>
<property
name="Usuario"
type="java.lang.String"
>
<column name="usuario" length="10" not-null="true" unique="true" sql-type="varchar" />
</property>
<property
name="Senha"
type="java.lang.String"
>
<column name="senha" length="10" not-null="true" sql-type="varchar" />
</property>
<property
name="Nome"
type="java.lang.String"
>
<column name="nome" length="100" not-null="true" sql-type="varchar" />
</property>
<property
name="IdEvento"
type="java.lang.Integer"
>
<column name="id_evento" length="11" not-null="true" sql-type="int" />
</property>
<property
name="Tipo"
type="java.lang.String"
>
<column name="tipo" length="10" not-null="true" sql-type="varchar" />
</property>
</class>
</hibernate-mapping>
no meu hibernate.cfg.xml esta assim:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.url">jdbc:mysql://10.84.227.173:3306/evento</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<mapping resource="br/com/maringa/eventosrel/Usuario.hbm.xml"/>
</session-factory>
</hibernate-configuration>
erro:
org.hibernate.exception.SQLGrammarException: could not load an entity: [br.com.maringa.eventosrel.Usuario#1]
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1269)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:139)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:124)
at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2453)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:387)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:368)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:166)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:140)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:119)
at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:571)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:59)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:80)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:133)
at br.com.maringa.eventosrel.Usuario$$EnhancerByCGLIB$$1be8f67.getNome(<generated>)
at TesteHibernate.main(TesteHibernate.java:58)
Caused by: java.sql.SQLException: Table 'evento.__usuario' doesn't exist
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2851)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1534)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1625)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2226)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1812)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1657)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:107)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1183)
at org.hibernate.loader.Loader.doQuery(Loader.java:363)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1255)
... 14 more