我与链接表中的其他列有多对多的关系.我的配置方式是拥有的一方吸引孩子们渴望(所以我没有得到LazyInitializationException)而在相反的方向上它是懒惰的.这有效.
我现在想要微调事务(在@TransactionalDAO和Service类的类级之前.我将方法设置getById为readOnly = true:
@Transactional(readOnly = true)
public Compound getById(Long id) {
return compoundDAO.getById(id);
}
Run Code Online (Sandbox Code Playgroud)
在此更改后,我得到一个LazyInitializationException以下代码段:
Compound compound = compoundService.getById(6L);
Structure structure = compound.getComposition().get(0).getStructure();
System.out.println("StructureId: "+ structure.getId()); // LazyInitializationException
Run Code Online (Sandbox Code Playgroud)
如果我删除(readOnly = true)这个作品!谁能解释这种行为?我使用Spring + Hibernate.有点令人困惑,因为我没有看到任何理由为什么这会影响加载哪些数据?
编辑:
关系定义的片段.这是一个多对多链接表中的列.
拥有方(例如化合物包含结构):
@OneToMany(fetch = FetchType.EAGER, mappedBy = "pk.compound",
cascade = CascadeType.ALL, orphanRemoval = true)
@OrderBy("pk.structure.id ASC")
private List<CompoundComposition> composition = new ArrayList<>();
Run Code Online (Sandbox Code Playgroud)
属于一边:
@OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.structure",
cascade = CascadeType.ALL)
@OrderBy("pk.compound.id …Run Code Online (Sandbox Code Playgroud) 如何使用php_ldap模块检查用户是否属于组?
我是ldap的新手,因此有点困惑......
通过谷歌搜索我到目前为止已经提出这个:
$ds=ldap_connect($ldapHost, $ldapPort);
if ($ds) {
$r=ldap_bind($ds, $ldapRdn, $ldapPassword);
$filter = "(sAMAccountName=" . $uid . ")";
$attr = array("memberof");
$result = ldap_search($ds, $ldapDN, $filter, $attr) or exit("Unable to search LDAP server");
Run Code Online (Sandbox Code Playgroud)
我不确定这是否正确,因为它是针对AD特定的soemthign.问题似乎是$ ldapDN.这是我搜索的权利吗?我的小组"定义"是:
cn=User,ou=Profiles,ou=App_DEV,ou=ApplicationRights,O=MyCompany.COM
Run Code Online (Sandbox Code Playgroud)
我怎么做这个检查?
编辑:
这是我的解决方案,在"接受的答案"和试验和错误的帮助下找到."我认为答案在很大程度上取决于您的具体系统.
//This is the User group DN
$ldapDN = "cn=User,ou=Profiles,ou=App_DEV,ou=ApplicationRights,O=MyCompany.COM";
$filter = "(uniqueMember=uid=" . $uid . ",ou=Users,O=MYCOMPANY.COM)";
$attr = array('uniqueMember');
$result = ldap_search($ldapConnection, $ldapDN, $filter, $attr):
$entries = ldap_get_entries($ldapConnection, $result);
ldap_unbind($ldapConnection);
return intval($entries["count"]) > 0;
Run Code Online (Sandbox Code Playgroud) 我找到了http://redquerybuilder.appspot.com/,但这会生成我希望避免的SQL客户端.在帽子页面上有一个指向JQuery Query Builder插件的链接,但该链接转到jquery主页.看起来这个插件不再存在了(另请参阅JQuery中的简单SQL查询生成器以获得相同的链接).
我找到了http://kindohm.com/posts/2013/09/25/knockout-query-builder/,它看起来非常符合我的要求,除了我不想添加另一个JavaScript库.
最后有http://devtools.korzh.com/easyquery/javascript/docs/javascript-query-builder-php,看起来非常好.但他们使用Web服务生成SQL,您必须获得一个API密钥才能生效.现在它是免费的...但看起来像一个很好的陷阱诱使用户,然后当他们不能轻易逃脱时,可能会开始收取Web服务或可以随时关闭它.
因此,在我构建自定义查询表单之前,是否存在这样的查询构建器?
线程间通信有问题,并通过在整个地方使用"虚拟消息"来"解决"它.这是一个坏主意吗?有哪些可能的解决方案
示例问题我有.
主线程启动一个线程进行处理并将记录插入数据库.主线程读取一个可能很大的文件,并将一个记录(对象)放在一个阻塞队列中.处理线程从队列中读取并确实有效.
如何告诉"处理线程"停止?队列可以是空的但是工作没有完成,主线程现在也没有处理线程完成工作并且不能中断它.
所以处理线程呢
while (queue.size() > 0 || !Thread.currentThread().isInterrupted()) {
MyObject object= queue.poll(100, TimeUnit.MILLISECONDS);
if (object != null) {
String data = object.getData();
if (data.equals("END")) {
break;
}
// do work
}
}
// clean-up
synchronized queue) {
queue.notifyAll();
}
return;
Run Code Online (Sandbox Code Playgroud)
和主线程
// ...start processing thread...
while(reader.hasNext(){
// ...read whole file and put data in queue...
}
MyObject dummy = new MyObject();
dummy.setData("END");
queue.put(dummy);
//Note: empty queue here means work is done
while (queue.size() > 0) {
synchronized …Run Code Online (Sandbox Code Playgroud) 我有一个多对多的关系,链接表有一个额外的字段.因此,根据以下教程,关系是通过2个一对多关系完成的:
我有2个实体,第三个实体定义了链接表并由@Embeddable ID字段组成.
这种关系定义为:
@OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.compound", cascade = CascadeType.ALL)
@OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.structure", cascade = CascadeType.ALL)
Run Code Online (Sandbox Code Playgroud)
是pk = @Embeddable ID字段.但是,当我打电话时,插入和删除工作正常
session.merge(compound);
Run Code Online (Sandbox Code Playgroud)
我得到一个StackOverflowError并且日志显示hibernate正在制作大量的select语句.请注意,数据库只包含1个关联,例如.1种含2种结构的化合物.看起来hibernate进入无限循环.
我也在http://giannigar.wordpress.com/2009/09/04/mapping-a-many-to-many-join-table-with-extra-column-using-jpa/上看过这个解决方案,但是如何你有更新吗?
在将此标记为重复之前,请先阅读问题.我已经阅读了有关此异常的所有内容,但它并没有为我解决问题.而且我确实得到了一个略有不同的异常,例如Another CacheManager with same name 'myCacheManager' already exists而不是Another unnamed CacheManager already exists.
Spring配置:
<cache:annotation-driven cache-manager="cacheManager"/>
<bean id="cacheManager"
class="org.springframework.cache.ehcache.EhCacheCacheManager"
p:cacheManager-ref="ehcache"/>
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
p:configLocation="ehcache.xml"
p:cacheManagerName="myCacheManager"
p:shared="true"/>
Run Code Online (Sandbox Code Playgroud)
的Ehcache
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="false" name="myCacheManager">
</ehcache>
Run Code Online (Sandbox Code Playgroud)
问题是我有1个(将来更多)测试安全性的测试类.这些类还加载了SecurityContext.xml
所以大多数测试类都有这样的注释:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:ApplicationContext.xml")
Run Code Online (Sandbox Code Playgroud)
然而导致问题的类:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:ApplicationContext.xml",
"classpath:SecurityContext.xml"
})
Run Code Online (Sandbox Code Playgroud)
似乎由于位置不同,上下文再次加载,但ehcacheManager仍然在以前的测试中处于活动状态.
注意:这只在运行多个测试时发生(例如,像clean + build).分别运行此测试类非常正常.
问题是什么?我该如何解决?
我有一个物化视图,我想在使用快速刷新的提交(来自按需)上改变.
但是我不断得到
ora-32337 cannot alter materialized view with pending changes refresh on commit
Run Code Online (Sandbox Code Playgroud)
甚至在刷新之后直接(并且知道没有进行任何更改).
可能是什么原因造成的?MV使用外连接,这可能是个问题吗?(MV日志适用于所有表格)
我有一个包含1列的pandas Dataframe,其中包含一串位,例如.'100100101'.我想将此字符串转换为numpy数组.
我怎样才能做到这一点?
编辑:
运用
features = df.bit.apply(lambda x: np.array(list(map(int,list(x)))))
#...
model.fit(features, lables)
Run Code Online (Sandbox Code Playgroud)
导致错误model.fit:
ValueError: setting an array element with a sequence.
Run Code Online (Sandbox Code Playgroud)
由于有明确的答案,我想出的解决方案适用于我的案例:
for bitString in input_table['Bitstring'].values:
bits = np.array(map(int, list(bitString)))
featureList.append(bits)
features = np.array(featureList)
#....
model.fit(features, lables)
Run Code Online (Sandbox Code Playgroud) 如何根据布尔值过滤 pandas 系列?
目前我有:
s.apply(lambda x: myfunc(x, myparam).where(lambda x: x).dropna()
Run Code Online (Sandbox Code Playgroud)
我想要的只是保留myfunc返回 true 的条目。myfunc是使用第三方代码的复杂函数,并且仅对单个元素进行操作。
我怎样才能让这个更容易理解?
我有一个动态的PHP页面,我需要使用get参数调用.然后,我想将生成的html放入一个字符串中,稍后再使用它(我正在尝试使用tonic框架进行Web服务)
所以这类似于PHP - 将动态生成(和回显)的HTML读入字符串?我尝试了使用cURL的答案.
问题是使用ntlm(apache mod_auth_sspi)完成身份验证.执行curl的php脚本已经过身份验证,例如,只有有效的用户才能执行它.以某种方式可以将这些"凭据"传递给cURL?(用户名可用但当然不是密码)
或者一个完全不同的方法也可以,但我只想创建一个创建带有html内容的字符串的函数.
$response = new Response($request);
$format = $request->mostAcceptable(array(
'json', 'html', 'txt'
));
switch ($format) {
case 'html':
$response->addHeader('Content-type', 'text/html');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/viewRecord.php?identifier=' . $identifier);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
$html = curl_exec($ch);
curl_close($ch);
$response->body = $html;
break;
//...
}
Run Code Online (Sandbox Code Playgroud)