我有一个看起来像这样的数据模型:
public class Item {
private List<ItemAttribute> attributes;
// other stuff
}
public class ItemAttribute {
private String name;
private String value;
}
Run Code Online (Sandbox Code Playgroud)
(这显然简化了很多无关紧要的东西)
我想要做的是创建一个查询来询问具有一个或多个特定属性的所有项目,理想情况下使用任意AND和OR连接.现在我保持简单,只是试图实现AND案例.在伪SQL(或伪HQL,如果你愿意),它将是这样的:
select all items
where attributes contains(ItemAttribute(name="foo1", value="bar1"))
AND attributes contains(ItemAttribute(name="foo2", value="bar2"))
Run Code Online (Sandbox Code Playgroud)
Hibernate文档中的示例似乎没有解决这个特定的用例,但它似乎是一个相当普遍的用例.分离案例也很有用,特别是我可以指定一个可能的值列表,即
where attributes contains(ItemAttribute(name="foo", value="bar1"))
OR attributes contains(ItemAttribute(name="foo", value="bar2"))
-- etc.
Run Code Online (Sandbox Code Playgroud)
这是一个适用于单个属性的示例:
return getSession().createCriteria(Item.class)
.createAlias("itemAttributes", "ia")
.add(Restrictions.conjunction()
.add(Restrictions.eq("ia.name", "foo"))
.add(Restrictions.eq("ia.attributeValue", "bar")))
.list();
Run Code Online (Sandbox Code Playgroud)
学习如何做到这一点将大大有助于扩展我对Hibernate潜力的理解.:)
我昨天刚升级到Mavericks,不得不为我的开发环境重新安装mod_jk.从源代码编译它有点痛苦.我在OS X 上发现了一个关于mod_jk 的先前问题的这个页面,但是还有一些额外的箍我不得不跳过.出于某种原因,apxs认为gcc生活在:
/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc
Run Code Online (Sandbox Code Playgroud)
但是那个确切的文件夹不存在; 我不得不对现有XcodeDefault.xctoolchain目录进行符号链接:
sudo ln -s XcodeDefault.xctoolchain/ OSX10.9.xctoolchain
Run Code Online (Sandbox Code Playgroud)
然后我尝试运行configure:
./configure CFLAGS='-arch x86_64' APXSLDFLAGS='-arch x86_64' --with-apxs=/usr/sbin/apxs
Run Code Online (Sandbox Code Playgroud)
但是,配置失败,因为它无法找到<stdio.h>,所以我将OS X 10.9工具链符号链接为:
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/ /usr/include
Run Code Online (Sandbox Code Playgroud)
然后,我可以通过sudo make install -f Makefile.apxs在apache-2.0子目录中运行来编译和安装模块.但是,当我启动Apache时sudo apachectl start,它立即崩溃了一个段错误:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff875fb866 __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007fff8b8a435c pthread_kill + 92
2 libsystem_c.dylib 0x00007fff92480bba abort + 125
3 libsystem_c.dylib 0x00007fff92480d31 abort_report_np + 181
4 libsystem_c.dylib 0x00007fff924a48c5 …Run Code Online (Sandbox Code Playgroud) 我正在编写一个java.beans.PropertyDescriptor使用Mockito的测试用例,我想模仿getPropertyType()返回任意Class<?>对象的行为(在我的例子中String.class).通常,我会通过调用:
// we already did an "import static org.mockito.Mockito.*"
when(mockDescriptor.getPropertyType()).thenReturn(String.class);
Run Code Online (Sandbox Code Playgroud)
然而,奇怪的是,这不编译:
cannot find symbol method thenReturn(java.lang.Class<java.lang.String>)
Run Code Online (Sandbox Code Playgroud)
但是当我指定类型参数而不是依赖于推理时:
Mockito.<Class<?>>when(mockDescriptor.getPropertyType()).thenReturn(String.class);
Run Code Online (Sandbox Code Playgroud)
一切都是笨拙的海鲂.为什么编译器在这种情况下无法正确推断when()的返回类型?我之前从未必须指定参数.
我是一个长期的Java人员,并且知道MANIFEST.MF在Jar 中的文件中引用的主类运行JAR的方法很简单:
java -jar theJar.jar
我正在使用它来启动Fabric3服务器(包含bin/server.jar在其标准发行版中).我注意到当我从分发tarball解压缩它时,它被标记为可执行文件.一时兴起,我试过了
./server.jar
从我的bash命令行(bashUbuntu 10.10中的4.1.5版本)开始,服务器启动就像我输入了正常的java -jar ...命令一样.JAR的结构类似于普通的JAR; 我做了一个head,并且#!在前几个字节中没有命令,所以bash不应该神奇地知道用它启动Java VM,对吧?或者这个版本的bash增长能否正确启动JAR并使用正确的清单?询问心灵想知道......
我正在进行一些测试驱动的开发,并在我的测试用例中添加了一个Mockito verify()调用,这样(为了保护无辜的代码,名称已更改):
Api api = mock(Api.class);
Thing thing = mock(Thing.class);
when(thing.getId()).thenReturn(1);
// later...
verify(api).doAThingWithAThingId(thing.getId())
Run Code Online (Sandbox Code Playgroud)
即使我没有将调用添加api.doAThingWithAThingId()到我的代码中,这个测试用例也会通过!但是,当我这样做的时候......
int id = thing.getId();
verify(api).doAThingWithAThingId(id);
Run Code Online (Sandbox Code Playgroud)
验证按预期失败.是什么导致了这种行为?
(为了记录,这是使用稍微旧版本的Mockito,1.8.4.)