0
我是Hibernate的新手,正在嘗試執行以下操作,但我得到unexpected token: :
錯誤。這肯定是一個菜鳥的錯誤,因爲我是一名新秀。我已經使用Vehicle類填充了表格。當我不使用命名參數時,此代碼正常工作。但我想知道它爲什麼不起作用。HQL中意外的令牌冒號
import java.util.Iterator;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.dono.util.SessionManager;
import org.javabrains.dono.dto.cascade.Vehicle;
public class HQL {
public static void main(String[] args) {
Session session = SessionManager.configureSessionFactory().openSession();
session.beginTransaction();
/*for (int i = 1; i <=10; i++) {
Vehicle vehicle = new Vehicle();
vehicle.setVehicleName("Car no. "+i);
session.save(vehicle);
}*/
String q="from :tabl";
Query query= session.createQuery(q);
query.setString("tabl", "Vehicle");
query.setFirstResult(3);
query.setMaxResults(2);
List<Vehicle> vehicles= (List<Vehicle>) query.list();
session.getTransaction().commit();
session.close();
for (Iterator<Vehicle> i = vehicles.iterator(); i.hasNext();) {
Vehicle car = (Vehicle) i.next();
System.out.println(car.getVehicleName());
}
}
}