我们正在将 java blazeds hibernate 与 flex 项目集成。首先我们在 eclipse 中测试了纯 java hibernate,它执行得很好。但是当我们将相同的内容放入 tomcat 与 blazeds 进行 flex 集成时,它会显示以下错误。这是唯一的错误。
Jan 24, 2013 11:31:31 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.6
Jan 24, 2013 11:31:31 AM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Jan 24, 2013 11:31:31 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Jan 24, 2013 11:31:31 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Jan 24, 2013 11:31:31 AM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Jan 24, 2013 11:31:31 AM org.hibernate.cfg.Configuration getConfigurationInputSt
ream
INFO: Configuration resource: /hibernate.cfg.xml
这是hibernate.cfg.xml(为了确定是否找不到hibernate.cfg.xml,我通过删除.cfg.xml的DOCTYPE进行测试,然后显示tomcat输出说找不到根元素......这意味着它能够找到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>
<property name="connection.url">jdbc:mysql://localhost/test</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<property name="current_session_context_class">thread</property>
<mapping class="com.model.User" />
<mapping class="com.model.UserDetails" />
<mapping class="com.model.LoanDetails" />
<mapping class="com.model.BorrowerDetails" />
</session-factory>
</hibernate-configuration>
这是hiberutil.java
public class HibernateUtil
{
private static SessionFactory sessionFactory=configureSessionFactory();
private static ServiceRegistry serviceRegistry;
private static SessionFactory configureSessionFactory() throws HibernateException {
Configuration configuration = new Configuration();
configuration.configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
}
public static SessionFactory getSessionFactory()
{
return sessionFactory;
}
}
为什么显示错误?控件来自 flex 端并执行 java 方法的起点...但是当涉及到休眠内容执行时,它在 tomcat 中显示此错误...
但是当我将 java+hibernate 作为纯 java 应用程序执行时,它执行得很好。
有谁能够帮助我?
谢谢
编辑 1 在@Andremoniy 建议的修改并将 .cfg.xml 放在 src 文件夹中之后,在 Eclipse 中它也可以工作,但不能在带有 flex 的 tomcat 中工作
出现以下错误
org.hibernate.MappingException: An AnnotationConfiguration instance is required
to use <mapping class="com.model.User"/>
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.jav
a:1606)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.jav
a:1561)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1540)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1514)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1434)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1420)
at com.sample.HibernateUtil.configureSessionFactory(HibernateUtil
.java:26)
at com.sample.HibernateUtil.<clinit>(HibernateUtil.java:20)
at com.sample.App.checkUser(App.java:34)