-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate tools: Could not find datasource
PostPosted: Thu Nov 20, 2008 2:49 pm 
Newbie

Joined: Thu Nov 20, 2008 2:14 pm
Posts: 3
Hi,

I'm trying to set up Hibernate tools to work in Eclipse.

I'm running Eclipse 3.4.1 and HibernateTools-3.2.4.Beta1. The stable version of the Hibernate tools seems to crash my Eclipse.

In the Hibernate tools configuration screen I have selected the JPA option and filled out the project name and the persistant unit. The database connection is [Hibernate configured connection].


Image

Here's the persistence.xml file:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for dev profile -->
<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="ritz">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/ritzDatasource</jta-data-source>
      <properties>
    <property name="hibernate.archive.autodetection" value="class, hbm" />     
         <property name="hibernate.cache.use_query_cache" value="true"/>
         <property name="hibernate.show_sql" value="false"/>
         <property name="hibernate.format_sql" value="true"/>
         <property name="hibernate.use_sql_comments" value="true"/>                 
         <property name="jboss.entity.manager.factory.jndi.name" value="java:/ritzEntityManagerFactory"/>
         <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect" />
         <property name="hibernate.default_schema" value="RITZ"/>
         <property name="hibernate.jdbc.batch_size" value="0"/>
      </properties>
   </persistence-unit>
   
</persistence>


the ritz-ds.xml file:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<datasources>
  <local-tx-datasource>
   
<local-tx-datasource>
    <jndi-name>ritzDatasource</jndi-name>
    <connection-url>jdbc:oracle:thin:@123.ete.test.net:1539:ritzd1</connection-url>
      <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
      <user-name>user</user-name>
      <password>password</password>
      <min-pool-size>1</min-pool-size>
      <max-pool-size>20</max-pool-size>
      <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name>
      <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>       
      <new-connection-sql>select * from dual</new-connection-sql>
      <check-valid-connection-sql>select * from dual</check-valid-connection-sql>     
      <metadata>
        <type-mapping>Oracle10g</type-mapping>
      </metadata>   
  </local-tx-datasource>
 
 
</datasources>



When I try to connect, this is the error message I get.

Image

Here's the stacktrace:

Code:
Error
Thu Nov 20 10:51:26 PST 2008
org.hibernate.HibernateException: Could not find datasource

org.hibernate.HibernateException: Could not find datasource
   at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:56)
   at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
   at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
   at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
   at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
   at org.hibernate.console.ConsoleConfiguration$3.execute(ConsoleConfiguration.java:395)
   at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:64)
   at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:93)
   at org.hibernate.console.ConsoleConfiguration.buildSessionFactory(ConsoleConfiguration.java:390)
   at org.hibernate.eclipse.console.workbench.LazySessionFactoryAdapter.getChildren(LazySessionFactoryAdapter.java:43)
   at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.getChildren(BasicWorkbenchAdapter.java:99)
   at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:105)
   at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:234)
   at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
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
   at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
   at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
   at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
   at javax.naming.InitialContext.lookup(InitialContext.java:351)
   at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
   ... 15 more



The configuration part loads my entities without problems, but the Session factory and Database don't seem to work.

It seems that the tool can't find the ritz-ds.xml file. Is there a way to link to that?


I've also tried to set up the database connection manually, instead of using the [Hibernate configured connection], but that doesn't seem to work either. I'm then able to connect to the database and get my tables to show up under the Database section in the tree, but the session factory still failing.

Any help that can point me in the right direction would be greatly appreciated. I've read most of the posts on the board remotely relevant to this, but couldn't get it to work.

Thanks.

Peter


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2008 6:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Hibernate tools run inside ant/eclipse we don't have access Application server specific datasources.

You can use a properties file to setup connection that will override the datasource usage or use latest build where we can point to a Eclipse DTP datasource.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2008 2:20 pm 
Newbie

Joined: Thu Nov 20, 2008 2:14 pm
Posts: 3
Thanks for the reply. I constructed a properties file that I'm referencing in the setup dialog above, in the "Property File" text box.

Code:
hibernate.connection.datasource = java:/ritzDatasource
hibernate.connection.url = jdbc:oracle:thin:@*******:1539/ritzd1
hibernate.connection.username = ****
hibernate.connection.password = *****
hibernate.transaction.factory_class = org.hibernate.transaction.JTATransactionFactory
hibernate.transaction.manager_lookup_class = org.hibernate.transaction.JBossTransactionManagerLookup
hibernate.dialect = org.hibernate.dialect.Oracle9Dialect


I think I'm missing something, since this isn't really working.

I have tried to set up a database connection and not going with the "Hibernate configured connection", and then I can access the database no problems, but the session factory complains about "Session factory error: Could not locate transaction manager".
I've even tried to add the hibernate3.jar to the classpath, but it didn't help either.

Btw, the version of the Hibernate tools I'm using is HibernateTools-3.2.4.Beta1-R200810311334. Is this not the latest one?

Thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2008 3:28 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
your properties file is still using Appserver dependent setup.

Here is an example of how to completely override any datasource setup in persistence.xml or cfg.xml (you might not need the last two but they at least make it explicilty you do not want a datasource or tx manager when using the tools)

Code:
#File used by hibernate tools to override <datasource> and other container specific settings in persistence.xml
hibernate.connection.password=
hibernate.connection.username=sa
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.connection.url=jdbc:hsqldb:.

hibernate.connection.provider_class=org.hibernate.connection.DriverManagerConnectionProvider
hibernate.datasource=
hibernate.transaction.manager_lookup_class=

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2008 2:07 pm 
Newbie

Joined: Thu Nov 20, 2008 2:14 pm
Posts: 3
Ok, I finally got it to work. I did have to add the hibernate.cache.use_query_cache property and set it to either blank or false for it to stop complaining about the second level cache.

Thanks again for all the help!

Code:
hibernate.connection.password=****
hibernate.connection.username=*****
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
hibernate.connection.url=jdbc:oracle:thin:@*****:1539:RITZD1
hibernate.connection.provider_class=org.hibernate.connection.DriverManagerConnectionProvider
hibernate.datasource=
hibernate.transaction.manager_lookup_class=

hibernate.cache.use_query_cache=false


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.