2 Replies Latest reply on Sep 22, 2005 2:47 AM by Tomek Staniszewski

    Cannot use other then default datasource for persistence.xml

    Tomek Staniszewski Newbie

      I've built a .par archive with persistence.xml and 25 entity beans. Connection parameters points to MS SQL server, however this is ignored by hibernate - default HSQL datasource is used instead. It's strange because changes in "hibernate.dialog" values are shown properly, but connection is skipped... The same happens when using <jta-data-properties>. What is wrong??? Am I doing something really stupid?
      I'm using ejb3 RC2 with jboss 4.03 RC2

      persistance.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <entity-manager>
       <name>sqlbzi</name>
      
       <class>pzu.bzi.db.bzi.Aplikacje</class>
       .... more classes
       <properties>
       <property name="hibernate.connection.url" value="jdbc:jtds:sqlserver://hhhhh:1433/iiii"/>
       <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
       <property name="hibernate.connection.driver_class" value="net.sourceforge.jtds.jdbc.Driver"/>
       <property name="hibernate.connection.password" value="xxxx"/>
       <property name="hibernate.connection.username" value="yyyy"/>
       </properties>
      </entity-manager>


      log looks like this:

      13:01:27,912 INFO [JaccHelper] Initialising JACC Context for deployment: sqlbzi.par
      13:01:28,144 INFO [Ejb3Deployment] Found persistence.xml file in EJB3 jar
      13:01:28,244 INFO [Environment] Hibernate 3.1 beta 3
      13:01:28,254 INFO [Environment] hibernate.properties not found
      13:01:28,259 INFO [Environment] using CGLIB reflection optimizer
      13:01:28,260 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling
      13:01:28,442 INFO [Ejb3Configuration] found EJB3 Entity bean: pzu.bzi.db.bzi.Aplikacje
      [ .... more entities found ]
      13:01:30,225 INFO [Configuration] processing extends queue
      13:01:30,233 INFO [Configuration] processing collection mappings
      13:01:30,238 INFO [CollectionBinder] Mapping collection: pzu.bzi.db.bzi.Typykostek.mddbs -> mddb
      [ .... more mappings ]
      13:01:30,255 INFO [Configuration] processing association property references
      13:01:30,255 INFO [Configuration] processing foreign key constraints
      13:01:30,920 INFO [Configuration] processing extends queue
      13:01:30,920 INFO [Configuration] processing collection mappings
      13:01:30,920 INFO [Configuration] processing association property references
      13:01:30,920 INFO [Configuration] processing foreign key constraints
      13:01:30,942 INFO [ConnectionProviderFactory] Initializing connection provider: org.hibernate.ejb.InjectedDataSourceConnectionProvider
      13:01:30,952 INFO [InjectedDataSourceConnectionProvider] Using provided datasource
      13:01:30,959 INFO [SettingsFactory] RDBMS: HSQL Database Engine, version: 1.8.0
      13:01:30,959 INFO [SettingsFactory] JDBC driver: HSQL Database Engine Driver, version: 1.8.0
      13:01:31,128 INFO [Dialect] Using dialect: org.hibernate.dialect.SQLServerDialect
      [... the rest is wrong, I want to use MS SQL, not build in HSQL ]


      Tomek Staniszewski

        • 1. Re: Cannot use other then default datasource for persistence
          Bill Burke Master

           

          "tstaniszewski" wrote:
          I've built a .par archive with persistence.xml and 25 entity beans. Connection parameters points to MS SQL server, however this is ignored by hibernate - default HSQL datasource is used instead. It's strange because changes in "hibernate.dialog" values are shown properly, but connection is skipped... The same happens when using <jta-data-properties>. What is wrong??? Am I doing something really stupid?


          #1 There is no such thing a <jta-data-properties>

          #2 You should be creating a JBoss datasource and referencing it in persistence.xml with
          jta-data-source

          #3 You should not be defining properties for connection management in hibernate

          #4 I could not reproduce your problem and the correct Dialect came up when I configured my persistence.xml correctly.


          modified persistance.xml:
          <?xml version="1.0" encoding="UTF-8"?>
          <entity-manager>
           <name>sqlbzi</name>
           <jta-data-source>java:/YourSQLServerDBConnectionPool</jta-data-source>
           <class>pzu.bzi.db.bzi.Aplikacje</class>
           .... more classes
           <properties>
           <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
           </properties>
          </entity-manager>



          Also, how are you packging your JAR? ARe you putting persistence.xml in META-INF? This may be your problem as well.



          • 2. Re: Cannot use other then default datasource for persistence
            Tomek Staniszewski Newbie

            Bill, thanks!
            #1 - typing error, my mistake. After using proper tag it still didn't work, but at least there were exceptions in log suggesting that there was a class loader problem. The driver was in both locations: jboss/lib and jboss/server/all/lib. Remove first occurence and voila! All works as expected.

            #3 Yes, I shoudn't. But I did - just taken this from manual :). And I am surprised that there is some kind of "drivers failover" - it seems that if hibernate fails to load user's declared driver then it loads it's own default hsql without any warning. One must read really carefully log to find it. This is really a minor issue.

            Thanks again!

            Tomek