hibernate properties not found
Asked Answered
S

4

10

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)
Selfexamination answered 24/1, 2013 at 6:16 Comment(7)
Hi, what is the error in your original question ? In the stack you pasted, I can only see hibernate.properties not found, which is not an error.Famished
In my origional question the execution stops by printing the stack i pasted and then no execution of query and no output..it ends like this...i put the show_sql to be true but that is not printed..Selfexamination
Have you checked the connection to your database?Famished
the same cfg.xml file that i used in tomcat also...in eclipse it is working perfectly as java application..Selfexamination
If you're using hibernate 3.x, did you try to use new AnnotationConfiguration() instead of new Configuration() in configureSessionFactory() ? (May need the additional dependancy to hibernate-annotationsAlphonsa
@Alphonsa i created maven hibernate project with jdk 1.7 plugin dependency and deployed into tomcat...previously annotationconfiguration was showing deprecated...now it is not showing any error..it worked perfectly fine..thanks for suggestionSelfexamination
As stated it is just a message. Hibernate by default at startup looks for hibernate.properties and hibernate.cfg.xml and logs a debug message if those aren't found.Atomize
S
1

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). 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.

Surgical answered 28/1, 2013 at 5:20 Comment(0)
Y
1

It seems to me, that you can solve this problem, by passing hibernate.cfg.xml directly into Configuration.

try (InputStream in = HibernateUtil.class.getResourceAsStream("/hibernate.cfg.xml")) {
     Configuration configuration = new Configuration().addInputStream(in).configure();
...
} ... 

The only thing, you have to properly point the path or class, for getResourceAsStream. Or you may be want to create InputStream using some relative path.

Yvetteyvon answered 24/1, 2013 at 7:2 Comment(4)
thanks. i am new to hibernate. but the getClass() is pointing error.Selfexamination
Actually yes, this was common example. I've changed it to HibernateUtil.class, but indeed this depends on where your hibernate.cfg.xml is located. Put into the package where HibernateUtil.java is placed.Yvetteyvon
@SamprityKashyap Where did you placed hibernate.cfg.xml file?Yvetteyvon
it is in src folder(with this it is working)..when i put it in package of hibernateutil class it shows following error INFO: HHH000021: Bytecode provider name : javassist java.lang.NullPointerException at org.hibernate.cfg.Configuration.add(Configuration.java:651) at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:685)Selfexamination
S
1

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). 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.

Surgical answered 28/1, 2013 at 5:20 Comment(0)
I
1

I have faced the same problem but I found the solution here..

http://www.mkyong.com/hibernate/hibernate-error-an-annotationconfiguration-instance-is-required-to-use/

ie. Change the line:

new Configuration().configure().buildSessionFactory();

to:

new AnnotationConfiguration().configure().buildSessionFactory();
Inpour answered 13/4, 2013 at 10:16 Comment(0)
K
1

if it is appeared that you use Intellij Idea you need to put hibernate.cfg.xml file into resources folder

ads

and if you will have after next error: org.hibernate.service.jndi.JndiException: Error parsing JNDI name []

delete in hibernate.cfg.xml file name of tag see picture:

enter image description here

Kush answered 14/5, 2017 at 12:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.