からエンティティマッピングを読み取らないセッションファクトリは、これが私のhibernate.cfgです:Hibernateは:hibernate.cfg.xmlの
<?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>
<!-- Connessione al database -->
<property name="connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<property name="connection.url">
jdbc:oracle:thin:@localhost:1521:xe
</property>
<!-- Credenziali -->
<property name="hibernate.connection.username">Test</property>
<property name="connection.password">Test</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">
org.hibernate.dialect.Oracle10gDialect</property>
<!-- DISABILITA AUTO COMMIT -->
<property name="hibernate.connection.autocommit">true</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">
org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">validate</property>
<!-- Entity -->
<mapping class= "it.test.Tbl1"></mapping>
<mapping class= "it.test.Tbl2"></mapping>
<mapping class= "it.test.Tbl3"></mapping>
<mapping class= "it.test.Tbl4"></mapping>
</session-factory>
</hibernate-configuration>
と、この休止utilのファイル:
私が実行しようとします単純なクエリ、私は例外を持って - > "クエリの例外:テーブルがマップされていない"。 しかし、私は、次のようにUTIL休止状態を変更した場合
public class HibernateUtil {
private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;
private static SessionFactory createSessionFactory() {
Configuration configuration = new Configuration();
configuration.configure();
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
}
public static SessionFactory getSessionFactory() {
if (sessionFactory == null)
sessionFactory = createSessionFactory();
return sessionFactory;
}
}
プログラムは成功で動作します。 セッションファクトリがコンフィグレーションファイルでロードされないのはなぜですか?
コンソールログ:
10:54:44.989 [main] DEBUG org.hibernate.hql.internal.ast.ErrorCounte-
throwQueryException() : no errors
10:54:45.130 [main] DEBUG
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker - select << begin
[level=1, statement=select]
org.hibernate.hql.internal.ast.QuerySyntaxException: Tbl1 is not mapped
[from Tbl1 eat where eat.activityId = :id]
at
org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException
(QuerySyntaxException.java:79)
at org.hibernate.QueryException.wrapWithQueryString
(QueryException.java:103)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile
(QueryTranslatorImpl.java:218)
私はこの問題は、このあると思う:
17:14:47.130 [main] DEBUG org.hibernate.internal.SessionFactoryRegistry -
Registering SessionFactory: a0044811-5a9f-483a-8ede-b136c9781bb3
(<unnamed>)
17:14:47.130 [main] DEBUG org.hibernate.internal.SessionFactoryRegistry -
Not binding SessionFactory to JNDI, no JNDI name configured
17:14:47.364 [main] DEBUG org.hibernate.stat.internal.StatisticsInitiator
- Statistics initialized [enabled=false]
あなたは私を助けることができます?
: "sessionFactory = configuration.addAnnotatedClass(Tbl1.class).addAnnotatedClass(Tbl2.class).addAnnotatedClass(Tbl3.class).addAnnotatedClass(Tbl4.class).buildSessionFactory(serviceRegistry);を追加するとプログラムがうまく動作します。 " しかし、私は、セッションファクトリがhibernate.cfg.xmlからマッピングクラスを読み込むことを望みます。私は、paserがhibernate.cfg.xmlのタグマッピングを読み込んでいないと思います。 – fegrieco
'hibernate.connection.username'の代わりに' connection.username'を試してみてください。 – SachinSarawgi
また、あなたの 'hibernate.cfg.xml'ファイルには閉じタグ' hibernate-configuration> 'がありません – SachinSarawgi