-->
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: How to supply JDBC Connection
PostPosted: Wed Jun 16, 2004 7:44 am 
Newbie

Joined: Mon Jun 14, 2004 3:24 am
Posts: 12
Hi.
I'm trying to connect to a Database using Hibernate and I get the following exception:

java.lang.UnsupportedOperationException: The user must supply a JDBC connection

I can create the JDBC Connection but I don't know how to supply it to Hibernate.

Regards
Miguel


Top
 Profile  
 
 Post subject: you can do it in 3 ways
PostPosted: Wed Jun 16, 2004 9:51 am 
Newbie

Joined: Wed Jun 09, 2004 2:41 pm
Posts: 14
By default when you create Configuration object, it looks for a file called
'hibernate.properties' in the classpath to read database and other information (like show_sql etc).

Or you can explicitly set it using config.setProperties(prop) method.

Or other way is when you create a session from the SessionFactory,
you can explicitly pass the connection object as
factory.openSession(conn).

Hope that helps,
Jeelani


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 9:53 am 
Newbie

Joined: Mon Jun 14, 2004 3:24 am
Posts: 12
Thanks a lot. I'll use last one


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 19, 2004 5:24 pm 
Newbie

Joined: Fri Jun 11, 2004 1:35 am
Posts: 18
Hello!!

I have this servlet:

protected void doProcess(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();

SessionFactory sessionFactory;
Configuration config;
Session session;

try{
InitialContext context = new InitialContext();
sessionFactory = (SessionFactory)context.lookup("java:/hibernate/HibernateFactory");
config = new Configuration();
config.addClass(Persona.class);
sessionFactory = config.buildSessionFactory();
session = sessionFactory.openSession();
Persona p = (Persona)session.get(Persona.class,new Integer("52717995"));
if(p!=null){
out.println(p.toString());
}
else{
out.println("Nula");
}
}
catch(Exception e){
out.println("Error:"+e.toString());
}

}
}

When I run Jboss server, already take the properties of hibernate, but when I launch my application appears this exception:

Error:java.lang.UnsupportedOperationException: The user must supply a JDBC connection

and in the console appears:

15:52:26,815 INFO [Configuration] Mapping resource: Persona/Persona.hbm.xml
15:52:26,915 INFO [Binder] Mapping class: Persona.Persona -> persona
15:52:26,915 INFO [Configuration] processing one-to-many association mappings
15:52:26,925 INFO [Configuration] processing one-to-one association property references
15:52:26,925 INFO [Configuration] processing foreign key constraints
15:52:26,925 WARN [SettingsFactory] No dialect set - using GenericDialect: The dialect was not set. Set the property hibernate.dialect.
15:52:26,925 INFO [Dialect] Using dialect: net.sf.hibernate.dialect.GenericDialect
15:52:26,925 INFO [SettingsFactory] Use outer join fetching: false
15:52:26,925 WARN [UserSuppliedConnectionProvider] No connection properties specified - the user must supply JDBC connections
15:52:26,925 INFO [TransactionManagerLookupFactory] No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
15:52:26,925 INFO [SettingsFactory] Use scrollable result sets: false
15:52:26,925 INFO [SettingsFactory] Use JDBC3 getGeneratedKeys(): false
15:52:26,925 INFO [SettingsFactory] Optimize cache for minimal puts: false
15:52:26,925 INFO [SettingsFactory] Query language substitutions: {}
15:52:26,925 INFO [SettingsFactory] cache provider: net.sf.ehcache.hibernate.Provider
15:52:26,925 INFO [Configuration] instantiating and configuring caches
15:52:26,925 INFO [SessionFactoryImpl] building session factory
15:52:27,015 INFO [SessionFactoryObjectFactory] no JNDI name configured

Thanks!!!!


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.