小编Lem*_*mmy的帖子

hibernate 5 sequencegenerator没有给出正确的值

迁移到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,但无济于事.任何帮助将不胜感激.

hibernate sequence hibernate-5.x

9
推荐指数
1
解决办法
7336
查看次数

在 Spring 中使用多个 HttpSessionIdResolver

我想将 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)

java spring spring-security

5
推荐指数
1
解决办法
1156
查看次数

使用Liquibase删除MySQL表

我只想在存在表的情况下使用Liquibase在MySQL中删除表。

我无法弄清楚如何检查Liquibase中是否存在表。

谢谢。

mysql sql database liquibase drop-table

4
推荐指数
1
解决办法
4642
查看次数

RememberMeAuthenticationFilter 和 Java Config:覆盖 onSuccessfulAuthentication 的自定义实现 - 如何以干净的方式做到这一点?

提供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)

java spring spring-security

3
推荐指数
1
解决办法
209
查看次数