我们正在将Javablazeeds hibernate与flex项目集成在一起。首先,我们在eclipse中测试了纯Javahibernate,并且执行良好。但是,当我们将相同的东西放入tomcat中进行火焰集成时,它会显示以下错误,这是唯一的错误。
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方法的起点…但是在hibernate东西执行时,它在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)
我想问题在于您提到的配置代码.hbm.xml可能无法在Tomcat中使用。
.hbm.xml
我认为它需要AnnotationConfiguration对象。我猜您由于Annotationconfiguration对象创建不起作用而使用了此代码。
AnnotationConfiguration
Annotationconfiguration
最好使用pom创建一个mavenhibernate项目,并将war文件导出到Tomcat(更改为Annotationconfiguration)。还可以使用log4jjar通过调试输出显示Tomcat执行的详细信息,以便Tomcat输出将打印所有执行流程。
war