java. Lang. unsupported operationexception: the application must provide a JDBC connection
•
Java
I wrote some code to test my hibernate configuration But I encountered this error message:
java.lang.UnsupportedOperationException: The application must supply JDBC connections at org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl.getConnection(UserSuppliedConnectionProviderImpl.java:61) at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:380) at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:228) at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:171) at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67) at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:162) at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1435) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(UnkNown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(UnkNown Source) at java.lang.reflect.Method.invoke(UnkNown Source) at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:356) at com.sun.proxy.$Proxy0.beginTransaction(UnkNown Source)
My file structure is as follows:
src ---test -------Test.java(with main function) -------User.java -------User.hbm.xml ----hibernate.cfg.xml
This is not a web application, it's just a normal java project hibernate. cfg. The XML is as follows:
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- Configure MysqL --> <property name="hibernate.connection.driver_class">com.MysqL.jdbc.Driver</property> <property name="hibernate.connection.URL">jdbc:MysqL://localhost:3306/mags</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">bysjysf</property> <property name="show_sql">true</property> <property name="hibernate.dialect">org.hibernate.dialect.MysqLDialect</property> <property name="hibernate.current_session_context_class">thread</property> <!-- Mapping Files --> <mapping resource="test/User.hbm.xml" /> </session-factory> </hibernate-configuration>
The main function codes are as follows:
public static void main(String[] args) { // TODO Auto-generated method stub Configuration cfg = new Configuration().configure("hibernate.cfg.xml"); StandardServiceRegistryBuilder sb = new StandardServiceRegistryBuilder(); sb.applySettings(cfg.getProperties()); StandardServiceRegistry standardServiceRegistry = sb.build(); SessionFactory sessionFactory = cfg.buildSessionFactory(standardServiceRegistry); Session session = sessionFactory.getCurrentSession(); System.out.println(session); Transaction tx = session.beginTransaction(); User user = new User(); user.setPassword("aaaa"); user.setUsername("ysf"); user.setAuthority(1); session.save(user); tx.commit(); session.close(); }
According to the error message, an error occurred
Transaction tx = session.beginTransaction();
I am a new user of hibernate. I have checked my configuration file many times Is there any one to help find out what the problem is? thank you!
Edit: Hibernate version is 4.3 five
Solution
Hibernate attribute names in configuration files are case sensitive
<property name="hibernate.connection.URL">
should
<property name="hibernate.connection.url">
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码