Ich bin neu zu überwintern und ich versuche, ein einfaches Programm zu schreiben, ich Fehler für diese Linie in Java-Code konfrontiert:java.lang.UnsupportedOperationException Der Antrag muss JDBC-Verbindungen liefern
session.beginTransaction();
dies mein hibernate.cfg.xml
Code:
<session-factory>
<!-- JDBC Database conncetion settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="conncetion.url">jdbc:mysql://127.0.0.1:3306/hb_student_tracker?useSSL=false</property>
<property name="conncetion.username">hbstudent</property>
<property name="connection.password">hbstudent</property>
<!-- JDBC conncetion pool settings ... using built-in test pool -->
<property name="conncetion.pool_size">1</property>
<!-- Select our SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Echo the SQL to stdout -->
<property name="show_sql">true</property>
<!-- set the current session context -->
<property name="current_session_context_class">thread</property>
</session-factory>
und die Java-Datei:
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.luv2code.hibernate.demo.entity.Student;
public class CreateStudentDemo {
public static void main(String[] args) {
//create session factory
SessionFactory factory = new Configuration()
.configure("hibernate.cfg.xml")
.addAnnotatedClass(Student.class)
.buildSessionFactory();
//create session
Session session = factory.getCurrentSession();
try{
// use the session object to save java object
//create a student object
System.out.println("Creating new student object");
Student tempStudent = new Student("Paul", "Wall", "[email protected]");
//start a transaction
session.beginTransaction();
//save the student object
System.out.println("Saving the student...");
session.save(tempStudent);
//commit transaction
session.getTransaction().commit();
System.out.println("Done!");
}
finally{
factory.close();
}
}
}
Ich benutze Hibernate 5.2.1 nur für den Fall. Ich überprüfte auch andere Fragen, aber keine von ihnen konnte helfen.
Was ist mit Ihrem Problem? oder irgendeine Fehlermeldung? –