-->
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.  [ 4 posts ] 
Author Message
 Post subject: Exception: The user must supply a JDBC connection
PostPosted: Wed Aug 09, 2006 7:44 am 
Newbie

Joined: Wed Aug 09, 2006 7:34 am
Posts: 3
Hi,

I am getting a 'UnsupportedOperationException' when i try to run a simple hibernate application. Can someone please help me with this.

Hibernate version: 2.x

Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
   
<hibernate-mapping>
   <class
      name="hello.Message"
      table="MESSAGES">
   
      <id
         name="id"
         column="MESSAGE_ID">
         <generator class="increment" />
      </id>
     
        <property
         name="text"
         column="MESSAGE_TEXT" />
     
     <many-to-one
         name="nextMessage"
         cascade="all"
         column="NEXT_MESSAGE_ID" />
   
   </class>
</hibernate-mapping>


Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
   "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
    <session-factory>
        <property name="connection.url">jdbc:oracle:thin:@10.122.83.99:1521:ROSTEST</property>
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.username">HIBERNATE</property>
        <property name="connection.password">HIBERNATE</property>
       
        <property name="c3p0.min_size">5</property>
        <property name="c3p0.max_size">20</property>
        <property name="c3p0.timeout">300</property>
        <property name="c3p0.max_statements">50</property>
        <property name="c3p0.idle_test_period">3000</property>

        <property name="show_sql">false</property>
        <property name="dialect">net.sf.hibernate.dialect.OracleDialect</property>

        <!-- Mapping files -->
       <mapping resource="hello/Message.hbm.xml" />
    </session-factory>
</hibernate-configuration>


Code between sessionFactory.openSession() and session.close():
Code:
         Configuration cfg = new Configuration().configure();
         //cfg.addResource("hello/Message.hbm.xml");
         cfg.setProperties(System.getProperties());
         SessionFactory sessions = cfg.buildSessionFactory();
         
         Session session = sessions.openSession();
         Transaction tx = session.beginTransaction();
         
         Message message = new Message("Hello World");
         session.save(message);
         
         tx.commit();
         session.close();


Full stack trace of any exception that occurs:
Code:
log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
   at net.sf.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:32)
   at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:289)
   at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3361)
   at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3321)
   at net.sf.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:40)
   at net.sf.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:19)
   at net.sf.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:2251)
   at hello.TestHibernate.main(TestHibernate.java:33)



Name and version of the database you are using:
Oracle 8i

TIA


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 9:25 am 
Newbie

Joined: Wed Aug 09, 2006 7:34 am
Posts: 3
To add to the above, if i make the following changes then it works fine. For some reason, the hibernate.cfg.xml file is not read properly.

Code:
         Configuration cfg = new Configuration().configure();
         //cfg.addResource("hello/Message.hbm.xml");
         System.setProperty("hibernate.connection.password","password");
         System.setProperty("hibernate.connection.username","username");
         System.setProperty("hibernate.connection.driver_class", "oracle.jdbc.driver.OracleDriver");
         System.setProperty("hibernate.connection.url", "jdbc:oracle:thin:@localhost:1521:SNAME");
         System.setProperty("hibernate.dialect", "net.sf.hibernate.dialect.OracleDialect");
         cfg.setProperties(System.getProperties());
         SessionFactory sessions = cfg.buildSessionFactory();


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 9:49 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
Code:
SessionFactory sessions = cfg.configure().buildSessionFactory();


which picks up information from hibernate.cfg.xml file and if you have last line as

Code:
SessionFactory sessions = cfg.configure( "some_hiber_config.xml" ).buildSessionFactory();


it will try to build SessionFactory by reading configuration properties from some_hiber_config.xml instead of hibernate.cfg.xml


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 10:11 am 
Newbie

Joined: Wed Aug 09, 2006 7:34 am
Posts: 3
Finally, got it resolved.

The below code fragment doesn't work
Code:
   Configuration cfg = new Configuration().configure();
   cfg.setProperties(System.getProperties());
   SessionFactory sessions = cfg.buildSessionFactory();


However, if i change the point at which configure is called to after the setProperties call, it works.
Code:
        Configuration cfg = new Configuration();
   cfg.setProperties(System.getProperties());
   SessionFactory sessions = cfg.configure().buildSessionFactory();


I have taken a look at the Configuration class and saw that the properties set by the configure call are being overridden by the call to setProperties. Assuming this is why it failed, i should be able to safely take out the call to setProperties on the Configuration object from the code.

Code:
        Configuration cfg = new Configuration();
   SessionFactory sessions = cfg.configure().buildSessionFactory();


Thanks for all the help. Wasted half a day on this :)


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