迁移到Hibernate 5.2.7后,我似乎得到了id字段的错误值.
我的代码:
@Id @SearchableId
@GeneratedValue(strategy=GenerationType.AUTO, generator="hms_seq_gen")
@SequenceGenerator(name="hms_seq_gen", sequenceName="patregn_seq")
protected Integer ID;
Run Code Online (Sandbox Code Playgroud)
Hibernate触发此查询:
select nextval ('patregn_seq')
它给出了5367.表中id字段的最后一个值是5358.
我明白了
ERROR: duplicate key value violates unique constraint "patientregistration_pkey"
[java] Detail: Key (id)=(5318) already exists.
我相信这个问题类似于这和这个,但我不得不问,因为给出的解决方案有没有为我工作:
我补充道
<property value="true" name="hibernate.id.new_generator_mappings"/>
到我的persistence.xml,但无济于事.任何帮助将不胜感激.
我想将 HTTPSessionIdResolver 用于“/api**”下的所有内容以及标准 CookieResolver 下的所有内容。
这怎么可能,以便两种配置使用不同的解析器?以我目前的方法,一切都使用 X-AUTH。
我试图理解 Spring 中的实现,最终在 SessionRepositoryFilter 中,但是这个过滤器只创建了一个实例,所以 der 只存在一个解析器。
@EnableWebSecurity
public class TestConfig {
@EnableSpringHttpSession
@Configuration
@Order(1)
public static class Abc extends WebSecurityConfigurerAdapter {
@Bean
@Primary
public HeaderHttpSessionIdResolver xAuth() {
return HeaderHttpSessionIdResolver.xAuthToken();
}
@Bean
@Primary
public MapSessionRepository mapSessionRepository(){
return new MapSessionRepository(new HashMap<>());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/service/json/**")
.authorizeRequests()
.anyRequest().authenticated()
.and()
.httpBasic()
.and()
.csrf()
.disable();
}
}
@EnableSpringHttpSession
@Configuration
@Order(2)
public static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@ConfigurationProperties(prefix = "spring.datasource")
@Bean …Run Code Online (Sandbox Code Playgroud) 我只想在存在表的情况下使用Liquibase在MySQL中删除表。
我无法弄清楚如何检查Liquibase中是否存在表。
谢谢。
提供AuthenticationSuccessHandlerfor aRememberMeAuthenticationFilter会破坏过滤器链,因此我想onSuccessfulAuthentication通过提供RememberMeAuthenticationFilter. 但是当使用简单的 Java Config 时,这似乎相当复杂或精细。
ApplicationEventPublisher如果需要访问HttpServletRequest或 ,则提供 an不是解决方案HttpServletResponse。
我设法做到了,但它看起来像一个黑客 - 有更好的方法吗?
我是这样做的:
http.rememberMe().addObjectPostProcessor(new ObjectPostProcessor<RememberMeAuthenticationFilter>() {
@Override
public <O extends RememberMeAuthenticationFilter> O postProcess(O object) {
RememberMeAuthenticationFilter newFilter = new RememberMeAuthenticationFilter(
(AuthenticationManager) getByReflection(object, "authenticationManager"),
(RememberMeServices) getByReflection(object, "rememberMeServices")
) {
@Override
protected void onSuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, Authentication authResult) {
// business logic
}
};
return (O) newFilter;
}
private <O extends RememberMeAuthenticationFilter> Object getByReflection(O object, String name) { …Run Code Online (Sandbox Code Playgroud)