При связывании с базой данных в Java и использовании getCriteriaBuilder
java.lang.IllegalArgumentException: Not an entity: class DataBase.entity.PlaceTable
При этом определен класс PlaceTable
:
@Entity
@Table( name = "place" )
public class PlaceTable {
@Id
@Column( name = "idplace" )
private int placeId;
@Column( name = "idparking")
private String parkingId;
@Column( name = "car" )
private boolean flagCar;
@Column( name = "bike" )
private boolean flagBike;
@Column( name = "truck" )
private boolean flagTruck;
@Column( name = "bus" )
private boolean flagBus;
@Column( name = "flag" )
private boolean empty;
@Column( name = "idcar" )
private String carId;
@Column( name = "timeBegin")
private int timeBegin;
Вот вызов обращения к базе
public ArrayList<PlaceTable> getWithCriteria( String field, String value ) throws HibernateException{
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery<PlaceTable> query = builder.createQuery(PlaceTable.class);
Root<PlaceTable> root = query.from( PlaceTable.class );
query.select(root).where(builder.equal( root.get( field ), value ) );
Query<PlaceTable> q = session.createQuery(query);
return ( ArrayList<PlaceTable> )q.getResultList();
}
Данное исключение выкидывается на строке Root<PlaceTable> root = query.from( PlaceTable.class );
Подключение к базе осуществляется посредством методов:
private static final String hibernate_show_sql = "true";
private final SessionFactory sessionFactory;
private static final String DB_DIALECT = "org.hibernate.dialect.MySQL5Dialect";
private static final String DB_DRIVER = "com.mysql.jdbc.Driver";
private static final String DB_URL = "jdbc:mysql://localhost:3306/mydb?useSSL=false";
private static final String DB_USERNAME = "root";
private static final String DB_PASSWORD = "geo";
public DBService() {
Configuration configuration = getMySqlConfiguration();
sessionFactory = createSessionFactory(configuration);
}
@SuppressWarnings("UnusedDeclaration")
private Configuration getMySqlConfiguration() {
Configuration configuration = new Configuration();
configuration.addAnnotatedClass(ParkingTable.class);
configuration.addAnnotatedClass(CarTable.class);
configuration.setProperty("hibernate.dialect", DB_DIALECT );
configuration.setProperty("hibernate.connection.driver_class", DB_DRIVER );
configuration.setProperty("hibernate.connection.url", DB_URL );
configuration.setProperty("hibernate.connection.username", DB_USERNAME );
configuration.setProperty("hibernate.connection.password", DB_PASSWORD );
configuration.setProperty("hibernate.show_sql", hibernate_show_sql );
return configuration;
}