例如,如果我做了类似的事情:
Criteria c = session.createCriteria(Book.class)
.add(Expression.ge("release",reDate);
.add(Expression.ge("price",price);
.addOrder( Order.asc("date") )
.setFirstResult(0)
.setMaxResults(10);
c.list();
Run Code Online (Sandbox Code Playgroud)
如何使用相同的条件实例,但删除(例如)第二个标准?我正在尝试构建一个动态查询,我想让用户删除一个过滤器,而后端不必从头开始重建标准.
谢谢
我正在尝试执行如下所示的求和SQL查询:
select group_ID, sum(case when user_type = 'Exec' then 1000
when user_type = 'Office' then 10 else 0 end)
from subscription
group by group_ID;
Run Code Online (Sandbox Code Playgroud)
使用来自Hiberate CriteriaBuilder查询的以下代码段:
criteriaBuilder.sum(
criteriaBuilder.selectCase()
.when(criteriaBuilder.equal(subscriptionJoin.get(Subscription_.userType), "Exec"),1000)
.when(criteriaBuilder.equal(subscriptionJoin.get(Subscription_.userType), "Office"),1)
.otherwise(101))
Run Code Online (Sandbox Code Playgroud)
但是出现以下编译错误:
类型参数'N'的推断类型'java.lang.object'不在其范围内; 应该扩展'java.lang.number'
知道如何使用selectCase支持执行求和吗?
SQL版本工作正常,我可以切换名为bar的布尔值...
mysql> update Foo set bar = ! bar WHERE id IN (1, 7, 13);
Query OK, 3 rows affected (0.02 sec)
Run Code Online (Sandbox Code Playgroud)
有没有一个简单的JPA查询等价,我试过
final Set<Integer> ids;
final Query query = em.createQuery("UPDATE " + Foo.class.getName()
+ " a set bar= !bar"
+ " where a.id in :ids");
query.setParameter("ids", ids);
query.executeUpdate();
Run Code Online (Sandbox Code Playgroud)
上面给出了一个org.hibernate.QueryException.
在我的实体中:
@Column(columnDefinition = "INTEGER", nullable = false)
private boolean bar;
Run Code Online (Sandbox Code Playgroud)
关于JPA语法的任何想法?
我收到以下错误:无法找到与from-view-id'/index.xhtml'匹配的导航案例,用于行动'#{medcontroller.getMedGeneric}',结果为'javax.faces.model.ListDataModel@7a652236'
我是jsf的新手,我对解决这个错误真的很无能为力.我有一个ManagedBean,代码如下:
MedController.java
@ManagedBean(name = "medcontroller")
@SessionScoped
public class MedController implements Serializable {
int startId;
String gName;
int endId;
DataModel medNames;
//DataModel medGeneric;
MedicineHelper helper;
private int recordCount = 1000;
private int pageSize = 10;
private Medicine current;
private int selectedItemIndex;
public MedController() {
helper = new MedicineHelper();
startId = 1;
endId = 10;
}
public MedController(int startId, int endId) {
helper = new MedicineHelper();
this.startId = startId;
this.endId = endId;
}
public Medicine getSelected() {
if (current == null) …Run Code Online (Sandbox Code Playgroud) 我想使用Hibernate的Criteria API来准确地说出每个人所说的最可能的用例,应用复杂的搜索条件.问题是,我想要查询的表不是完全由原始值组成,而是部分来自其他对象,我需要查询这些对象的id.
我从2年前发现这篇文章表明这是不可能的.以下是我尝试无效的方法,还有Hibernate的其他方面,我知道字符串文字中支持这种点符号的位置,以指示对象嵌套.
if (!lookupBean.getCompanyInput().equals("")) {
criteria.add(Restrictions.like("company.company", lookupBean.getCompanyInput() + "%"));
}
Run Code Online (Sandbox Code Playgroud)
编辑:
这是我正确考虑的代码,用于完成我上面尝试的内容,使用下面第一个答案的建议; 请注意,我甚至使用额外的createCriteria调用来对另一个关联的对象/表中的属性进行排序:
if (!lookupBean.getCompanyValue().equals("")) {
criteria.createCriteria("company").add(
Restrictions.like("company", lookupBean.getCompanyValue() + "%"));
}
List<TrailerDetail> tdList =
criteria.createCriteria("location").addOrder(Order.asc("location")).list();
Run Code Online (Sandbox Code Playgroud) 我正在尝试撤回一组具有特定类型项目的项目列表.
例如:
<class name="Owner" table="OWNER">
<id name="id" column="OWNER_ID" />
<set name="cats" table="OWNER_CATS" lazy="false">
<key column="OWNER_ID" />
<many-to-many class="Cat" />
</set>
Run Code Online (Sandbox Code Playgroud)
<class name="Cat" table="CAT" discriminator-value="C">
<id name="id" column="CAT_ID" />
<discriminator column="type" type="character" />
<subclass name="Lion" discriminator-value="L">
<property name="teeth" />
</subclass>
</class>
Run Code Online (Sandbox Code Playgroud)
使用限制如何获得有狮子作为宠物的所有者列表?
我尝试过以下几点无济于事:
criteria.createCriteria("cats").add(Restrictions.eq("class", Lion.class));
Run Code Online (Sandbox Code Playgroud) 我必须在特定字段myProperity上创建创建标准或标准(在类MyClass上).我必须选择prop = null或满足特定条件的所有对象.所以我应该做类似的事情:
Criteria criteria = this.sessionManager.getCurrentSession().createCriteria(MyClass.class);
specificCriteria = criteria.createCriteria('myProperity');
/* definition of specificCriteria */
Disjunction disjunction = Restrictions.disjunction();
disjunction.add(Restrictions.isNull('myProperity'));
disjunction.add(specificCriteria);
criteria.add(disjunction);
Run Code Online (Sandbox Code Playgroud)
问题是由事实造成的:
你有什么想法如何处理它?
我正在为汽车经销商开发 Web 应用程序。我有一个包含一组安全枚举的字段的 Car 类。
public class Car {
@Id
@GeneratedValue
private Long id;
@NotNull(message = "{year}")
@Min(value = 1950)
@Max(value = 2020)
@Column(nullable = false)
private int year;
@NotNull()
@Column(nullable = false)
private String make;
@NotNull()
@Column(nullable = false)
private String model;
@NotNull()
@Min(value = 0)
@Max(value = 1000000)
@Column(nullable = false)
private int kilometres;
@Column(nullable = false)
private int price;
@NotNull()
@Enumerated(EnumType.STRING)
private Gearbox gearbox;
@ElementCollection(fetch = FetchType.EAGER)
@Enumerated(EnumType.STRING)
@CollectionTable(name="SECURITY")
@Column(name="TYPE")
private Set<Security> securityList = new HashSet<Security>();
@NotNull() …Run Code Online (Sandbox Code Playgroud) 我是hibernate的新手,并试图在hibernate中运行查询,但我得到了异常
unexpected token: ON near line 1, column 135 [SELECT A.comp_id.appRefNo ....
Run Code Online (Sandbox Code Playgroud)
这是代码
StringBuffer query = new StringBuffer("SELECT A.comp_id.appRefNo,
A.comp_id.custId from ");
query.append(LosaCustContactZ.class.getName());
query.append(" A INNER JOIN " + LosaCust.class.getName() + " B
ON ( B.comp_id.appRefNo = A.comp_id.appRefNo AND " +
"B.comp_id.custId = A.comp_id.custId) INNER JOIN " + LosaApp.class.getName() + " C
ON " + "(B.comp_id.appRefNo = A.comp_id.appRefNo) ");
query.append("WHERE C.comp_id.appRefNo != ?" + " AND C.appDt >= ? AND
A.contactT = 'PHONE'" );
if (StringUtils.isNotEmpty(phoneNums)) {
query.append(" AND A.contact …Run Code Online (Sandbox Code Playgroud) 我需要清除数组列表,哪一种方法更好?为什么?
方法1:
List list = new ArrayList();
list.add("ram");
if(list!=null)
{
list.clear();
}
Run Code Online (Sandbox Code Playgroud)
方法2:
List list = new ArrayList();
list.add("ram");
if(list!=null && !list.isEmpty())
{
list.clear();
}
Run Code Online (Sandbox Code Playgroud)
在方法1中,我不检查列表是否为空,直接我已经清除了列表.
但是在方法2中,如果列表不是空的,我已经通过检查清除了列表
if(list!=null && !list.isEmpty())
Run Code Online (Sandbox Code Playgroud)
哪一种方法更好?方法1还是方法2?