F
Furtano
Gast
Hallo ich möchte eine Abfrage die SELECT mit ORDER BY ausführt.
Ich versuchte mein bestes aber ich komme nicht weiter.
Warum funktionierts nicht?
Danke für eure Hilfe
Ich versuchte mein bestes aber ich komme nicht weiter.
Warum funktionierts nicht?
Danke für eure Hilfe

PHP:
public List<?> sortByAttribute (Class clazz, String attribute, Boolean DESC){
String order = "";
if (DESC)
order = "DESC";
else
order = "ASC";
Query q = em.createQuery("SELECT o FROM " + clazz.getCanonicalName() + " o ORDER BY " + attribute + " " + order);
return q.getResultList();
}
Hibernate: select article0_.id as id1_, article0_.actionprice as actionpr2_1_, article0_.category_id as category9_1_, article0_.description as descript3_1_, article0_.film_lenght as film4_1_, article0_.name as name1_, article0_.picture as picture1_, article0_.price as price1_, article0_.version as version1_ from Article article0_
Hibernate: select category0_.id as id2_0_, category0_.category as category2_0_ from Category category0_ where category0_.id=?
Hibernate: select category0_.id as id2_0_, category0_.category as category2_0_ from Category category0_ where category0_.id=?
Hibernate: select category0_.id as id2_0_, category0_.category as category2_0_ from Category category0_ where category0_.id=?
package maxweiss.htw.kbe.spring.minimalistic_mvc_example.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import lombok.Data;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
@Entity // tell jpa that its an entity
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Data public class Article {
@Id
@GeneratedValue
private long id;
@ManyToOne
// @JoinColumn(name = "CATEGORY_ID")
private Category category;
private int version;
private String name;
private String description;
private int film_lenght;
private double price;
private double actionprice;
private String picture;
}