我在添加新用户/ pwd时尝试添加一个盐,但文档似乎缺少如何执行此操作.
这是一个基本的例子:
<authentication-manager>
<authentication-provider user-service-ref="userDetailsService">
<password-encoder hash="md5">
<salt-source user-property="username"/>
</password-encoder>
</authentication-provider>
</authentication-manager>
Run Code Online (Sandbox Code Playgroud)
您可以通过示例看到,既未使用自定义salt或自定义密码编码器.
那么,在添加新用户/ pwd时,如何连接Salt?我认为这将是:
@Autowired SaltSource saltSource;
protected void foo(final CustomUser user) {
final PasswordEncoder encoder = new Md5PasswordEncoder();
user.setPassword(encoder.encodePassword(user.getPassword(), saltSource));
}
Run Code Online (Sandbox Code Playgroud)
但是,由于我使用的是默认的salt/password编码器,而且我没有自定义的salt bean,因此autowire会失败.
任何线索如何使这项工作?
我试图确定ImmutableList的最佳实践.以下是一个简单的例子,有助于解决我的问题:
例如:
public ImmutableCollection<Foo> getFooOne(ImmutableList<Foo> fooInput){
//.. do some work
ImmutableList<Foo> fooOther = // something generated during the code
return fooOther;
}
public Collection<Foo> getFooTwo(List<Foo> fooInput){
//.. do some work
List<Foo> fooOther = // something generated during the code
return ImmutableList.copyOf(fooOther);
}
public void doSomethingOne(){
ImmutableCollection<Foo> myFoo = getFooOne(myList);
...
someOtherMethod(myFoo);
}
public void doSomethingTwo(){
Collection<Foo> myFoo = getFooOne(myList);
...
someOtherMethod(myFoo);
}
Run Code Online (Sandbox Code Playgroud)
我的问题:
哪个在应用程序中最有意义?[doSomethingOne和getFooOne]或[doSomethingTwo和fooTwo]?换句话说,如果你知道你正在使用ImmutableCollections,那么继续来回和执行copyOf(),或者只是在各地使用Immutable是有意义的吗?
这些示例是公共方法,可能意味着其他人使用它们.如果这些方法是私有的并且在内部使用,那么这些答案会改变吗?
如果用户尝试向不可变List添加任何内容,则将抛出异常.因为他们可能没有意识到这一点,显然返回一个ImmutableCollection而不是Collection会更有意义吗?
我正在使用Hibernate 4.1.6并且存在构建列表的速度问题.我正在运行以下查询.
public void doQuery(final Baz baz){
final Query query = getSessionFactory().getCurrentSession().createQuery(
"select c.id, foo.someValue from Foo as foo "+
"join foo.a as a"+
"join foo.b as b "+
"join b.c as c "+
"where baz=:baz"
);
query.setParameter("baz", baz);
Long start=System.currentTimeMillis();
final List<Object[]> list = query.list();
Long end=System.currentTimeMillis();
System.out.println((end-start));
}
Run Code Online (Sandbox Code Playgroud)
我设置了hibernate调试以获取发送到数据库的实际查询.我直接在数据库中运行了该查询,并在0.015毫秒内返回了23,000行.所以,我猜测查询不是问题.上面的示例显示创建该列表需要大约32秒.有什么办法可以加快速度吗?
更新:我尝试使用hibernate调试查询使用createSQLQuery()方法,它的运行速度与createQuery()方法一样慢.
更新:我尝试使用无状态会话,但运行速度一样慢.
更新:我输出了一些统计信息(将hibernate.generate_statistics标志设置为true)但没有任何看起来令我担心:
Hibernate SessionFactory Statistics [
Number of connection requests[4]
Number of flushes done on the session (either by client code or by hibernate[3]
The number of completed …Run Code Online (Sandbox Code Playgroud) 我想知道哪个更有效率,为什么?
1)
List<Blah> foo;
...
return ImmutableList.copyOf(foo);
Run Code Online (Sandbox Code Playgroud)
要么
2)
List<Blah> foo;
...
return new ImmutableList.Builder<Blah>().addAll(foo).build();
Run Code Online (Sandbox Code Playgroud) 我有以下设置,它给我一条消息,指出"构造函数调用Overridable方法".我知道这种情况正在发生,但我的问题是如何修复它以便代码仍然有效并且消息消失了.
public interface Foo{
void doFoo();
}
public class FooImpl implements Foo{
@Override{
public void doFoo(){
//.. Do important code
}
}
public class Bar{
private FooImpl fi;
public Bar(){
fi = new FooImpl();
fi.doFoo(); // The message complains about this line
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
我发生了最奇怪的事情,我无法弄明白为什么.描述这个的最好方法是提供一个简单的例子:
@Service
@Transactional
public class Foo{
public ModelAndView delete(@ModelAttribute("abc") Long id) {
ModelAndView mav = new ModelAndView();
try {
getDaoService().delete(id); //Calls Bar.delete()
} catch (final Exception e) {
// Add a custom error message to the mav for the user to see
mav.getModelMap().addAttribute(blah, blah);
}
return mav;
}
}
@Service
@Transactional
public class Bar {
public void delete(final E entity) throws HibernateException {
if (null != entity) {
try {
sessionFactory.getCurrentSession().delete(entity);
} finally {
sessionFactory.getCurrentSession().flush();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在这种特殊情况下,我试图删除一个具有约束违规的对象(ORA-02292).我希望删除失败,因为这个.当删除失败时,我希望向用户显示适当的自定义消息. …
我正在使用Spring Security 3.1并且正在使用
<concurrency-control max-sessions="1" error-if-maximum-exceeded="true" />
Run Code Online (Sandbox Code Playgroud)
有没有办法在浏览器关闭时强制关闭会话?我需要将max-sessions保持为1以进行并发控制.
谢谢!
我想知道为延迟加载的对象加载嵌套值的最佳方法是什么.我提供了一个例子来帮助解释这个问题.
public class A{
private B b; //Lazy loaded
private C c; //Lazy loaded
private D d; //Lazy loaded
}
public class B{
private E e; //Lazy loaded
private F f; //Lazy loaded
}
public class C{
}
public class D{
}
Run Code Online (Sandbox Code Playgroud)
作为一个例子我想做:
System.out.println(a.getB().getE());
Run Code Online (Sandbox Code Playgroud)
如果我运行上面的语句,我会得到一个延迟加载异常.
我总能做到以下几点:
for (A a : somePossiblyLargeList) {
org.hibernate.Hibernate.initialize(a.getB().getE());
}
Run Code Online (Sandbox Code Playgroud)
但显然性能会很糟糕.
有没有办法可以编写自定义HQL查询,该查询返回预先填充了这些特定嵌套字段的对象?
谢谢!
I am trying to create a unique identifier for every row of a view. The view I have joins a lot of tables and therefore no one table's primary key will help me identify the row.
Doing a google search it looks like I may be able to achieve this by using rowid? But I'm not sure how to reference the view's rowid. Below is an example of how I envisioned rowid would work, but it obviously fails with an …
是否可以使用来自hibernate的Oracle'with'子句?
我有以下基本示例:
final String queryStr =
" with v_tbl as ( "+
" select distinct etc...";
final Query query = getSessionFactory().getCurrentSession().createQuery(queryStr);
final List results = query.list();
Run Code Online (Sandbox Code Playgroud)
我得到以下异常:
ERROR org.hibernate.hql.PARSER - line 1:2: unexpected token: with
Run Code Online (Sandbox Code Playgroud)
我读了一篇建议切换到的文章:
<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>
Run Code Online (Sandbox Code Playgroud)
但这似乎没有帮助.
有什么建议?
fyi,我正在使用Hibernate 3.6.7,Spring 3.0.6,Oracle 11g
我正在艰难地绕着以下情况缠头.解释的最佳方式可能是例子
我有一个Map <Column,Set <Row >>对象.假设它包含以下数据:
ColumnA['abc','def']
ColumnB['efg','hij','klm']
ColumnC['nop']
ColumnD['qrs','tuv','wxy','zzz']
Run Code Online (Sandbox Code Playgroud)
我正在尝试生成以下输出:
Row1[abc,efg,nop,qrs]
Row2[abc,efg,nop,tuv]
Row3[abc,efg,nop,wxy]
Row4[abc,efg,nop,zzz]
Row5[abc,hij,nop,qrs]
Row6[abc,hij,nop,wxy]
etc...
Run Code Online (Sandbox Code Playgroud)
所以在这种情况下总共会有24行.
但是,列数和行数都是动态的.我觉得这需要以某种方式递归地进行,但我不知道从哪里开始.
任何帮助,将不胜感激.
更新 - 我做了一个似乎有用的树结构.
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
Set<DefaultMutableTreeNode> curNodes = new HashSet<DefaultMutableTreeNode>();
curNodes.add(root);
final Set<Column> keys = map.keySet();
for (final Column key : keys) {
final Set<Row> rowSet = map.get(key);
Set<DefaultMutableTreeNode> tmpNodes = new HashSet<DefaultMutableTreeNode>();
for (final Row row : rowSet) {
DefaultMutableTreeNode curNode = new DefaultMutableTreeNode();
curNode.setUserObject(row);
tmpNodes.add(curNode);
for (DefaultMutableTreeNode n : curNodes) {
n.add(curNode);
}
}
curNodes …Run Code Online (Sandbox Code Playgroud) 我知道这有点模糊,但我对观点不熟悉,并试图了解他们的能力.
假设我使用表的组合创建由复杂查询创建的视图.如果我试图在视图中编辑一条记录,那么视图是否足够智能,可以向后通过创建视图的逻辑并在正确的表中编辑正确的值?
是否在视图中编辑了一个值?
谢谢!