I want to create a hibernate SQL query and cast it to an object without creating the table.
for example i have
StringBuilder query = new StringBuilder();
query.append("SELECT groupId, categoryId, name FROM AssetCategory");
SQLQuery sqlQuery = session.createSQLQuery(query.toString());
sqlQuery.addEntity("Categories", Categories.class);
List<Categories> list = sqlQuery.list();
The category object is declared like this :
@Entity
public class Categories implements Serializable {
@Column(name = "name")
String name;
@Column(name = "categoryId")
Long categoryId;
@Column(name = "groupId")
Long groupId;
Of course this cant work because there is no ID. And this table does not need to be created either. So how would i go about declaring this ?
Any hints ?
I just cant find the documentation.
you can use a SQLTransformer to do this.. you wont need the annotations in the pojo even.
read this. it will help you realize what you should be doing.