-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Does Junit works with Hibernate?
PostPosted: Wed Sep 12, 2012 3:22 am 
Newbie

Joined: Fri Mar 16, 2012 12:08 pm
Posts: 5
I have a java application with Hibernate as ORM. Now is time to test the application. I want to use Junit (I used time ago and I thought I knew how its works :s). The first problem I find is creating an instance of a DaoImpl class where the method which retrieve data is (and I want to test this method). The error I got doing "new" is: java.Lang.ExceptionInitializerError. I think its come because of the class of the instance has Hibernate classes, try to connect to the DataBase and so on... and probaly I cannot create a instance of this class as easy because of hibernate in back.

If this, can annyone give a reference to configure for junit works with Hibernate. I find Hiberante with Spring. Is not valid to me because spring is not implemented in my application.

thanks all!!


Top
 Profile  
 
 Post subject: Re: Does Junit works with Hibernate?
PostPosted: Wed Sep 12, 2012 5:39 am 
Newbie

Joined: Fri Mar 16, 2012 12:08 pm
Posts: 5
More in detail the exactly problem is:

@Test
public void testBuscaTramitesPorAgrupacion(){
// dao = new EstadisticasDAOImpl();

Session session = HibernateUtil.getSessionFactory().openSession(); "Line throw exception"
Criteria criteria = session.createCriteria(UsuarioLogin.class);
List<UsuarioLogin> listaUsuarios = null;

When test reach the line where session is created its thrown this exception:
java.lang.ExceptionInInitializerError
at utiles.hibernate.HibernateUtil.buildSessionFactory(HibernateUtil.java:26)
at utiles.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:10)
at estadisticas.EstadisticasDaoImplTest.testBuscaTramitesPorAgrupacion(EstadisticasDaoImplTest.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NullPointerException
at utilidades.mensajes.Claves.getObjetoDeContextoAplicacion(Claves.java:203)
at utilidades.web.OegamExcepcion.obtenerMensajeDeFichero(OegamExcepcion.java:143)
at utilidades.web.OegamExcepcion.<init>(OegamExcepcion.java:119)
at utilidades.mensajes.GestorFicherosPropiedades.getMensaje(GestorFicherosPropiedades.java:38)
at utiles.hibernate.HibernateUtil.buildSessionFactory(HibernateUtil.java:17)
... 18 more

Its compile fine. Its in runtime when fails.

The test folder is within the project with hibernate libraries are and DaoImpl classes to make query does.


Top
 Profile  
 
 Post subject: Re: Does Junit works with Hibernate?
PostPosted: Wed Sep 12, 2012 6:27 am 
Newbie

Joined: Fri Mar 16, 2012 12:08 pm
Posts: 5
It was my fail ^_^

The connection to the DB was looking for the hibernate.properties which is in the Apache project. Just copying this file to the test folder of the propel project it works fine.

You can close the thread.

Thanks anyway!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.