Hibernate console & java.lang.ClassNotFoundException

Hello,
I'm trying to run queries in the Hibernate Console, but no matter which Entity I try, I get

java.lang.ClassNotFoundException:
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Class.java:169)
 at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
 at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:84)
 at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:143)
 at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:84)
 at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:459)
 at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:90)
 at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2863)
 at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)



What am I doing wrong?

Thanks
--
llappall
0

Hello.

It means Hibernate (BTW, is it 3.6.n?) can't find JDBC driver class. Please make sure that jar(s) containing the driver classes is added to your module's dependencies.

Regards,
Alexander.

0
Avatar
Permanently deleted user

My JDBC driver is present in the Dependencies tab of my module like this:

Maven: com.oracle:ojdbc6:11.2.0.3   -> Compile

Changed it to Provided and didn't work. Do I need to add the dependency not as a Maven dependency?

Notice that I can use the DataSource to create Entities but then I get the ClassNotFoundException when running the console. I've tried to find where to tell the Console to use that DataSource but haven't found it. Are those independent?

Thanks for your quick answer.

--
llappall

Message was edited by: llappall

0

In this case please check your Hibernate facet settings (in Project Structure dialog). Check DataSource Mapping section: what data source is hibernate config mapped to. Does this data source definition refer necessary driver jars?

Thanks,
Alexander.

0
Avatar
Permanently deleted user

It's working now. For documentation purposes, I'll explain.

My module had a JPA facet, not a Hibernate one. I recreated the JPA facet with the Default JPA Provider set to Hibernate, and then I was able to set the data source.
The data source can be set in the <module> -> Facet 'JPA' in the Project Structure screen.

Thanks for the help.
--
llappall

1

Hello, I have the same problem with spring boot - I have not persistence.xml - how can I add the data source in this case?

0

请先登录再写评论。