tags:

views:

209

answers:

1

hi i'm using ireport 3.7.2 with ejbql connection my problem is that when i test the connection, fails because Could not find datasource, in the log says:

Caused by: org.hibernate.HibernateException: Could not find datasource

Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

I guees can be the jndi.properties that in the wrong directory, i tried put into java_home/lib but doesn't work

+1  A: 

Finally after a lot of work i made the ejbql connection with ireport. Follow this steps to do it!!

1) i'm using jboss 4.2.3, so if you using glashfish or other server, find the libraries that match with the jboss that i'm using

2) You need to find in your jboss directory server/default/lib the follow libraries:

  • hibernate3.jar
  • hibernate-entitymanager.jar
  • jboss-common.jar
  • hibernate-annotations.jar
  • ejb3-persistence.jar
  • jboss.jar

3) copy the libraries previously named and copy your ireport installation directory in this path \Jaspersoft\iReport-3.7.2\ireport\modules\ext and replace it, note that the library call hibernate-common-annotation and jpa.jar need to be erase from that path. You need to do it because this library creates conflicts with hibernate-annotations and ejb3-persistence.jar.

4) get the jar of your project and copy it in your in this example let's called example-core.jar to the installation directory in the path \Jaspersoft\iReport-3.7.2\ireport\libs

5) modify the jar the persistence.xml of your project (in our case "example.jar") and sets with this next properties,

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="example" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>/jdbc/example</non-jta-data-source>
<properties>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/>
</properties>
</persistence-unit>
</persistence>

6)Go to ireport and add the libraries to the classpath, in tools, options in the tab of classpath

7) go to the installation directory of ireport in the path Jaspersoft\iReport3.7.2\ireport\modules open the jar called com-jaspersoft-ireport with winrar or other tool , and go to META-INF/MANIFEST.INF in the part of Class-Path modify the name of the library "hibernate-common-annotation.jar" (renember you erase this library) for the "hibernate-annotations.jar"

8)Go to Jboss_home/server/default/deploy and modify the datasource xml of your project and put this configuration, (renember in this example the project is call "example" and the datasource should be called example-ds.xml)

<datasources>
<local-tx-datasource>
<jndi-name>jdbc/example</jndi-name>
<use-java-context>false</use-java-context>
<connection-url>jdbc:oracle:thin:@localhost:1521:XE</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>example</user-name>
<password>example</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>

Note that the property usa-java-context in false is that allow you to access to the data source outside of the jboss in our case from ireport

9)go to the ireport and add the follow libraries into the ireport classpath

  1. jnp-client.jar
  2. jboss-client.jar
  3. jbossall-client.jar
  4. the database driver in my case ojdbc.jar (for oracle)
  5. jboss-ejb3x.jar

10) sets your jndi.properties and put it into the jar hibernate-entitymanager.jar

11) Now run the jboss, go to ireport and create the ejql connection, in the persistence unit name sets the name that place in the persistence.xml of the jar located in installation directory Jaspersoft\iReport-3.7.2\ireport\libs, in this case the persistence unit name is "example" without the quotes marks

I hope that this help to somebody or someone jeje, i know that's pretty hard, and sorry for my english its not my first language

Jorge