没有找到休眠属性 [英] hibernate properties not found

查看:142
本文介绍了没有找到休眠属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在将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
一月24,2013 11:31:31 AM org.hibernate.cfg.Environment< clinit>
INFO:找不到hibernate.properties
一月24,2013 11:31:31 org.hibernate.cfg.Environment buildBytecodeProvider
INFO:Bytecode提供程序名称:cglib
Jan 24 ,2013 11:31:31 AM org.hibernate.cfg.Environment< clinit>
INFO:使用JDK 1.4 java.sql.Timestamp处理
一月24,2013 11:31:31 AM org.hibernate.cfg.Configuration configure
INFO:从资源配置:/ hibernate。 cfg.xml
2013年1月24日上午11:31:31 org.hibernate.cfg.Configuration getConfigurationInputSt $ b $ ream
INFO:配置资源:/hibernate.cfg.xml

这是hibernate.cfg.xml(要确定是否找不到hibernate.cfg.xml,而且我通过删除DOCTYPE的.cfg.xml然后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\"&b $ b< hibernate-configuration>
<会话工厂>
< propert y 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连接池(使用内建) - >
< property name =connection.pool_size> 1< / property>

< property name =current_session_context_class>线程< / 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

{



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;




$ b

为什么错误显示?这个控件来自于flex端,并且执行了java方法的起始点...但是当涉及到hibernate的执行时,它会在tomcat中显示这个错误...



但是,当我执行java + hibernate作为一个纯java应用程序,它正在执行罚款。

有人可以帮我吗?

谢谢

编辑1修改@Andremoniy建议的修改后,把.cfg.xml放在src文件夹中,这里也是在eclipse中,不在tomcat中用flex

以下的错误来了

  org.hibernate .MappingException:需要AnnotationConfiguration实例
才能使用< 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)
在org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1540)
在org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1514)
在org.hibernate .cfg.Configuration.configure(Configuration.java:1434)
在org.hibernate.cfg.Configuration.configure(Configuration.java:1420)
在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中工作...我认为它需要AnnotationConfiguration对象。我猜你使用了这个代码,因为Annotationconfiguration对象创建不工作。更好的方法是用pom创建一个maven hibernate项目,然后将war文件导出到tomcat(通过Annotationconfiguration的更改)...还可以使用log4j jar来显示细节的tomcat执行与调试输出。所以tomcat输出将打印所有的执行流程

we are integrating the java blazeds hibernate with flex project..First we tested the pure java hibernate in eclipse and it is executing fine. But when we put the same in tomcat for flex integration with blazeds it is showing the following error.this is the only error.

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

this is the hibernate.cfg.xml(To identify whether hibernate.cfg.xml is not found and i tested by deleting DOCTYPE of .cfg.xml then tomcat output displayed saying the root element is not found...which means it is able to find the hibernate.cfg.xml( i think)

 <?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>

this is 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;
    }
}

why the error is showing? the control is coming from flex side and executing the starting point of the java method...but when it comes to hibernate stuff execution, it is showing this error in tomcat...

But when i execute java+hibernate as a pure java application it is executing fine..

can anybody help me?

Thanks

EDIT 1 After the modification suggested by @Andremoniy and putting the .cfg.xml in src folder and here also in eclipse it is working but not in tomcat with flex

following error comes

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)

解决方案

I guess the problem is with the code for configuration you mentioned for .hbm.xml may not be working in tomcat...i think it needs AnnotationConfiguration object. i guess you used this code due to the Annotationconfiguration object creation is not working.Better create a maven hibernate project with pom and export the war file to tomcat(with the changes of Annotationconfiguration)...and also use log4j jar for showing the details of tomcat execution with the debug outputs.So that tomcat output will print all of execution flow

这篇关于没有找到休眠属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆