cancel
Showing results for 
Search instead for 
Did you mean: 

Web Dynpro: Where put hibernate hibernate.cfg.xml?

Former Member
0 Kudos

I have seen several people asking about the place to put the config file of Hibernate, but not any conclusive answer until now...

I created a external library in WAS (I verified using Visual Admin that the lib was correctly deployed). In my Web Dynpro References -> Library Reference I add the library in the format Provider Name/Library Name: "sap.com/hiblibs"

<b> Where can I store the hibernate.cfg.xml?</b> I have tried put it in all web dynpro folders!

Thanks,

Ivan Garcia

From Brazil

<b> This is my source code:</b>

Configuration cfg = new Configuration();

cfg.configure("hibernate.conf.xml");

<b> The error:</b>

org.hibernate.HibernateException: hibernate.conf.xml not found

at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)

at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1402)

at org.hibernate.cfg.Configuration.configure(Configuration.java:1424)

I have read all forum topics about this, including:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/bf0d57db-0c01-0010-6fa3-83503981...

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/2ae0614a-0601-0010-a491-a9a635f0...

/people/bala.krishnan2/blog/2006/09/25/bid-adieu-to-bots--using-captchas

/people/valery.silaev/blog/2005/09/14/a-bit-of-impractical-scripting-for-web-dynpro

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Ivan,

Did you try to put this file right under src/packages?

If so, please check whether or not it get included in EAR/JAR after build.

Also try to rename it to hibernate.cfg.hbml and use cfg.configure("hibernate.conf.hbml") -- some NW IDE resist to include files with xml extension, so it's necessary to fake them.

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

Message was edited by:

Valery Silaev

Gstoiljkovski
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Ivan,

you need to make sure you place the configuration file where the application server's class loader will find it. If you are running Web Dynpros (or any other web application), you may put it under WEB-INF/classes of your web module.

You may have J2EE applications without any web components - for example if you intend to only provide business logic for web services or rich clients. In this case you may not have any web modules, but will probably have some kind of EJB jars or such. The Hibernate POJOs are a more natural part of such jars rather then WARs (web modules). In this case you can put them under the root of this JAR. The class loader of the SAP J2EE Engine will load any property file placed in the class path of the class loader - whether it's a flat text file or an xml file. WEB-INF/classes or WEB-INF/lib is always in the class path of the (application) class loader.

There is one thing you have to be aware of though. I do not know which version of Hibernate you are working with, but if you look at the source code of hibernate (the binaries are in the hibernate.jar) you will see that, the method Configuration.configure() without any argument will try to load the hibernate.cfg.xml from the current path - which means, the hibernate.jar and the hibernate.cfg.xml will have to reside under the same folder. But you do not seem to do this, so it is OK. This applies to versions of the NetWeaver 6.40 or 6.40s. Most likely this also applies to the new JEE 5 preview version of the NetWeaver application server also available for download on SDN, since to my knowledge the class loadign concepts have not been changed. But I have not tested this yet.

Beyond the How-To-Guide about running Hibernate on NetWeaver (or SAP J2EE Engine) 6.40 we have also provided a sample application and its source code as IDE projects. Take a look at them and you will find the hibernate.cfg.xml file in the deployable EAR.

I hope this answers your question and my comment has been helpful to you.

Cheers, Goran

Former Member
0 Kudos

Very thanks, Goran,

We will try again, following your orientation.

Ivan

Answers (1)

Answers (1)

luciano_leitedasilva
Contributor
0 Kudos

Ivan,

I've faced with this error and I solved using the following way:

1 - Create a DC library Project - Put the hibernat's jar files at this project and create a public part. Don't forget to create an assembly and build component.

2 - Create a DC Java Projet - Put all Hibernat classes at this project (POJOS, Comands and Utils) and the library project as "used DC". Put the hibernate.cfg.xml over the src/package folder. Create a public part.

3 - Create a DC Web Dynpro - Add the hibernate and java project as used DC.

Create a Java Bean Model and create the applications. In your web dynpro code, just call the Commands classes.

Build the web dynpro DC and do its deploy!

At this way will work fine.

Regards,

Luciano

Former Member
0 Kudos

Hi / olá, Luciano,

This solution is good, but I dont know how to implement it in a existing Web Dynpro project. For a new DC Web Dynpro project, ok; but how convert a existing Web Dynpro Project to a DC Web Dynpro?

Luciando, eu tinha tentando essa alternativa. Mas como transformar um projeto Web Dynpro pré-existente num projeto DC Web Dynpro? Eu tentei simplesmente criar um projeto DC Web Dynpro e depois copiar a aplicação, as views e as pastas do projeto Web Dynpro "tradicional" para o primeiro. Mas deram alguns erros e eu achei que não seria o melhor caminho. Mas partindo do zero acho que a sua é realmente a melhor solução ou pelo menos a mais fácil de implementar. Vc já integrou o Hibernate num projeto Web Dynpro "tradicional" (não-DC)? Perdoe-me se eu escrever algo muito absurdo, mas até ontem eu nunca tinha usado um projeto DC Web Dynpro.

Thanks / Obrigado

luciano_leitedasilva
Contributor
0 Kudos

Ivan,

I suggest to use DC at all projects (Web Dynpro, Java, Enterprise Java, Web Services,...) even in small projects. I've tried to use Hibernate at a non DC Project, but it was unsuccessfully. I guess that this is possible, but I don't know how do this!

To convert your actual WD project to DC Project, you can just copy the src folder of your local project and replace it in the DC project.

1. Create a WD DC Project.

2. Copy the src folder of the local project.

3. Go to your local file system where you have created your DC project. Navigate to the src folder.

4. Paste the copied src folder.

5. Go to ur NWDS. Refresh the DC project.

Hence you will get the local converted to a DC project.

Regards/Abraços!

Luciano

Former Member
0 Kudos

Luciano, Goran and Valery completely clarify my options related to the integration Hibernate-Web Dynpro.

Thanks to all!