-->
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.  [ 1 post ] 
Author Message
 Post subject: Sax Parsing Error - programmatic configuration 3.6.0-Final
PostPosted: Thu Jan 19, 2012 12:52 pm 
Newbie

Joined: Thu Jan 19, 2012 12:02 pm
Posts: 1
When calling Configuration.configure(), I keep getting the error
Quote:
org.xml.sax.SAXParseException: Element type "hibernate-mapping" must be declared


I have been trying to work through this for several days, and my configuration and mapping files validate against their respective DTDs. I'm begginging to suspect that we have some bizzare issue with an older parser on the classpath or that there is something wrong with doing programmatic configuration in WebLogic. In the hopes I have made a boneheaded mistake, I am posting these here to see if anyone will recognize the issue. Thanks in advance!

Note: We are attempting to plug in our own datasource provider and session connection factory to continue using some custom failover and datasource resolution code. If you notice any typos below it's likely a mistake I made while censoring anything that could be used to identify my employer.

Here's the hibernate.cfg.xml (much of this should be ignored since we are programmatically configuring and attempting to use a custom datasource provider):
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
  <session-factory>
        <property name="hibernate.bytecode.use_reflection_optimizer">false</property> 
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
        <property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
        <property name="show_sql">true</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@host:port:schema</property>         
        <property name="hibernate.connection.username">username</property>
        <property name="hibernate.connection.password">******</property>
        <property name="hibernate.connection.provider_class">com.myCompany.CustomDataSourceConnectionProvider</property>

        <mapping resource="com/myCompany/db/hibernate/Users.hbm.xml"/>
   </session-factory>
</hibernate-configuration>


Contents of /com/myCompany/db/Users.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd//hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="com.mycompany.db.hibernate.Users" table="Users">
        <id name="logonId" column="LOGON_ID" type="java.lang.String" >
            <generator class="assigned" />
        </id>
    <!-- other columns removed for clarity -->
    </class>
</hibernate-mapping>


snippet from where the error occurs: com.myCompany.CustomDataSourceConnectionProvider:
Code:
     
      DataSource dataSource = ServiceLocator.getDefaultDataSource(inDb);

      theLogger.debug("datasource = " + dataSource);

      //Are there any other properties hibernate will require?
      Properties props = new Properties();
      props.put("DATASOURCE", dataSource);
      props.put("DATABASE_KEY", inDb);
      props.put(Environment.CONNECTION_PROVIDER, "com.MyCompany.db.hibernate.CustomDataSourceConnectionProvider");
      props.put("hibernate.bytecode.use_reflection_optimizer", "false");
      props.put("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
      props.put("hibernate.connection.driver_class", "oracle.jdbc.OracleDriver");
      props.put("show_sql", "true");
      props.put("hibernate.connection.url", "jdbc:oracle:thin:@host:port:schema");         
      props.put("hibernate.connection.username", "username");
      props.put("hibernate.connection.password", "********");
      props.put("hibernate.use_sql_comments", "true");

      //Set the properties
      Configuration config = new Configuration();
      config.setProperties(props);
      Configuration configDone = config.configure();  //BOOM - throws sax parsing exception


com.MyCompany.db.hibernate.CustomDataSourceConnectionProvider:
Code:
com.MyCompany.db.hibernate;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.connection.DatasourceConnectionProvider;

import com.MyCompany.ejb.client.DatabaseVO;
import com.MyCompany.ejb.util.ServiceLocator;

/**
* The CustomDataSourceConnectionProvider provides a mechanism for injecting our own data source and
* handles our cmnm failover mechanism.
*
* @author
*/
public class CustomDataSourceConnectionProvider extends
    DatasourceConnectionProvider
{
  private static Logger theLogger = Logger.getLogger(CustomDataSourceConnectionProvider.class);

  public final static String DATASOURCE = "DATASOURCE";
  public final static String DATABASE_KEY = "DATABASE_KEY";
  private DatabaseVO myDatabaseVO;
 
  public void configure(Properties props) throws HibernateException
  {
    theLogger.debug("configuring...");   
    DataSource ds  = (DataSource)props.get(DATASOURCE);
    theLogger.debug("got our data source: " + ds);
    this.setDataSource(ds);
    myDatabaseVO = (DatabaseVO)props.get(DATABASE_VO);
    theLogger.debug("got our databaseVO: " + myDatabaseVO);
  }

  @Override
  public Connection getConnection() throws SQLException
  {
    try
    {
      theLogger.debug("getConnection called");
      Connection conn = getDataSource().getConnection();
      theLogger.debug("got a connection:" + conn);
      return conn;
    }
    catch (Exception e)
    {
      //If we got an error and it was for the **** db, try the failover ****, but do not change our datasource
      // permanently because as soon **** is back we want to switch back over to it.
      if (ServiceLocator.get******().getDBName().equals(myDatabaseKey.getDBName()))
      {
        DatabaseName failover = ServiceLocator.getReplicatedDB();
        DataSource newDS = ServiceLocator.getDefaultDataSource(failover);
        return newDS.getConnection();
      }
      else throw new SQLException(e.getMessage());
    }
  }
 
  @Override
  public void closeConnection(Connection conn) throws SQLException
  {
    theLogger.debug("closeConnection called");
    //this will return to the WLS pool.
    conn.close();
  }
}


If I do not call configure(), the code executes correctly all the way through getting a connection, but then blows up because it does not recognize the Users entity.


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

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.