Mình mới học về java web, IDE là intelliJ.
Mình chạy install ở Lifecycle trên cái project maven nhỏ của mình thì nó bị lỗi như này, mọi người có ai giải thích nó bị gì được không ạ.
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project toeic-core-test: There are test failures.
Please refer to /Users/tranthanhtung/IdeaProjects/toeicOnline/toeic-core-test/target/surefire-reports for the individual test results.
Còn mà chạy debug thì nó lỗi /hibernate.cfg.xml not found
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<!-- thông tin kết nối đến database -->
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/toeiconline?autoReconnect=true</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">1234</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<!-- Danh sách các XML mapping file-->
<mapping class="vn.myclass.core.persistence.entity.RoleEntity"/>
<mapping class="vn.myclass.core.persistence.entity.UserEntity"/>
<mapping class="vn.myclass.core.persistence.entity.CommentEntity"/>
<mapping class="vn.myclass.core.persistence.entity.ListenGuideLineEntity"/>
</session-factory>
</hibernate-configuration>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="TestAll">
<test name="case1">
<classes>
<class name="vn.myclass.core.test.RoleTest" />
</classes>
</test>
</suite>
Đây là cái Hibernate của mình
package vn.myclass.core.common.ultils;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory(){
try {
//Create a sessionFactory from hibernate.cgf.xml
return new Configuration().configure().buildSessionFactory();
}catch (Throwable e){
System.out.println("Initial session factory failed");
throw new ExceptionInInitializerError(e);
}
}
public static SessionFactory getSessionFactory(){
return sessionFactory;
}
}
package vn.myclass.core.data.daoimpl;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import vn.myclass.core.common.ultils.HibernateUtil;
import vn.myclass.core.data.dao.GenericDao;
import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.List;
public class AbstractDao <ID extends Serializable, T> implements GenericDao <ID, T> {
private Class<T> persistenceClass;
public AbstractDao() {
this.persistenceClass = (Class<T>) ((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[1];
}
public String getPersistenceClassName() {
return persistenceClass.getSimpleName();
}
protected Session getSession(){
return HibernateUtil.getSessionFactory().openSession();
}
public List<T> findAll() {
List<T> list = new ArrayList<T>();
Transaction transaction = null;
try {
transaction = getSession().beginTransaction();
//HQL
StringBuilder sql = new StringBuilder("from ");
sql.append(this.getPersistenceClassName());
Query query = this.getSession().createQuery(sql.toString());
list = query.list();
transaction.commit();
}catch (HibernateException e) {
transaction.rollback();
throw e;
}
return list;
}
}
Mong được giúp đỡ, cảm ơn mọi người !