How can I use hibernate annotation filter in spring boot?












0














I'd like to use hibernate annotiation filter for my spring boot backend, i'm using repos to get the data from the database and i don't know why i get only the unfiltered elements, i configured the entities with the filter annotation and enabled the filter in the controller. Does anyone know what is missing? Or has anyone some experince with using the @filter in spring boot?



@CrossOrigin(value = "http://localhost:**")
@RestController
public class MyController {
public MyController(EntityManagerFactory entityManagerFactory) {
this.sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
}


public class MyController {
public MyController(EntityManagerFactory entityManagerFactory) {
this.sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
}

@ModelAttribute("id")
public String getMandatortId(@RequestAttribute String id) {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
Filter mandator_filter = session.enableFilter("equalId");
mandator_filter.setParameter("id", id);
return id;
}}



@Entity
@Table(name = "openuser", schema = "arego", catalog = "")
@FilterDef(name = "equalId", parameters = {@ParamDef(name = "id", type = "string")})
@Filters( {@Filter(name = "equalId", condition id = :id")})
@IdClass(PatientEntityPK.class)
public class OpenuserEntity {}









share|improve this question
























  • I guess doesn't work means your entities get loaded without being filtered here?
    – Xtreme Biker
    Jul 20 '18 at 6:13










  • Yes that's my problem
    – lia1812
    Jul 20 '18 at 6:14










  • So you'd better edit the question to be more specific about the issue. Also I guess Spring Boot and Maven have nothing to do here, it's an Hibernate specific.
    – Xtreme Biker
    Jul 20 '18 at 6:16








  • 1




    Thanks for your hint!
    – lia1812
    Jul 20 '18 at 6:17










  • In your question: FilterDef name= equalId, but in in @Filter name=equaId (without "l"). Typo?
    – Mark Bramnik
    Jul 24 '18 at 5:25
















0














I'd like to use hibernate annotiation filter for my spring boot backend, i'm using repos to get the data from the database and i don't know why i get only the unfiltered elements, i configured the entities with the filter annotation and enabled the filter in the controller. Does anyone know what is missing? Or has anyone some experince with using the @filter in spring boot?



@CrossOrigin(value = "http://localhost:**")
@RestController
public class MyController {
public MyController(EntityManagerFactory entityManagerFactory) {
this.sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
}


public class MyController {
public MyController(EntityManagerFactory entityManagerFactory) {
this.sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
}

@ModelAttribute("id")
public String getMandatortId(@RequestAttribute String id) {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
Filter mandator_filter = session.enableFilter("equalId");
mandator_filter.setParameter("id", id);
return id;
}}



@Entity
@Table(name = "openuser", schema = "arego", catalog = "")
@FilterDef(name = "equalId", parameters = {@ParamDef(name = "id", type = "string")})
@Filters( {@Filter(name = "equalId", condition id = :id")})
@IdClass(PatientEntityPK.class)
public class OpenuserEntity {}









share|improve this question
























  • I guess doesn't work means your entities get loaded without being filtered here?
    – Xtreme Biker
    Jul 20 '18 at 6:13










  • Yes that's my problem
    – lia1812
    Jul 20 '18 at 6:14










  • So you'd better edit the question to be more specific about the issue. Also I guess Spring Boot and Maven have nothing to do here, it's an Hibernate specific.
    – Xtreme Biker
    Jul 20 '18 at 6:16








  • 1




    Thanks for your hint!
    – lia1812
    Jul 20 '18 at 6:17










  • In your question: FilterDef name= equalId, but in in @Filter name=equaId (without "l"). Typo?
    – Mark Bramnik
    Jul 24 '18 at 5:25














0












0








0







I'd like to use hibernate annotiation filter for my spring boot backend, i'm using repos to get the data from the database and i don't know why i get only the unfiltered elements, i configured the entities with the filter annotation and enabled the filter in the controller. Does anyone know what is missing? Or has anyone some experince with using the @filter in spring boot?



@CrossOrigin(value = "http://localhost:**")
@RestController
public class MyController {
public MyController(EntityManagerFactory entityManagerFactory) {
this.sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
}


public class MyController {
public MyController(EntityManagerFactory entityManagerFactory) {
this.sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
}

@ModelAttribute("id")
public String getMandatortId(@RequestAttribute String id) {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
Filter mandator_filter = session.enableFilter("equalId");
mandator_filter.setParameter("id", id);
return id;
}}



@Entity
@Table(name = "openuser", schema = "arego", catalog = "")
@FilterDef(name = "equalId", parameters = {@ParamDef(name = "id", type = "string")})
@Filters( {@Filter(name = "equalId", condition id = :id")})
@IdClass(PatientEntityPK.class)
public class OpenuserEntity {}









share|improve this question















I'd like to use hibernate annotiation filter for my spring boot backend, i'm using repos to get the data from the database and i don't know why i get only the unfiltered elements, i configured the entities with the filter annotation and enabled the filter in the controller. Does anyone know what is missing? Or has anyone some experince with using the @filter in spring boot?



@CrossOrigin(value = "http://localhost:**")
@RestController
public class MyController {
public MyController(EntityManagerFactory entityManagerFactory) {
this.sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
}


public class MyController {
public MyController(EntityManagerFactory entityManagerFactory) {
this.sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
}

@ModelAttribute("id")
public String getMandatortId(@RequestAttribute String id) {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
Filter mandator_filter = session.enableFilter("equalId");
mandator_filter.setParameter("id", id);
return id;
}}



@Entity
@Table(name = "openuser", schema = "arego", catalog = "")
@FilterDef(name = "equalId", parameters = {@ParamDef(name = "id", type = "string")})
@Filters( {@Filter(name = "equalId", condition id = :id")})
@IdClass(PatientEntityPK.class)
public class OpenuserEntity {}






hibernate spring-boot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 24 '18 at 11:40

























asked Jul 20 '18 at 5:36









lia1812

61




61












  • I guess doesn't work means your entities get loaded without being filtered here?
    – Xtreme Biker
    Jul 20 '18 at 6:13










  • Yes that's my problem
    – lia1812
    Jul 20 '18 at 6:14










  • So you'd better edit the question to be more specific about the issue. Also I guess Spring Boot and Maven have nothing to do here, it's an Hibernate specific.
    – Xtreme Biker
    Jul 20 '18 at 6:16








  • 1




    Thanks for your hint!
    – lia1812
    Jul 20 '18 at 6:17










  • In your question: FilterDef name= equalId, but in in @Filter name=equaId (without "l"). Typo?
    – Mark Bramnik
    Jul 24 '18 at 5:25


















  • I guess doesn't work means your entities get loaded without being filtered here?
    – Xtreme Biker
    Jul 20 '18 at 6:13










  • Yes that's my problem
    – lia1812
    Jul 20 '18 at 6:14










  • So you'd better edit the question to be more specific about the issue. Also I guess Spring Boot and Maven have nothing to do here, it's an Hibernate specific.
    – Xtreme Biker
    Jul 20 '18 at 6:16








  • 1




    Thanks for your hint!
    – lia1812
    Jul 20 '18 at 6:17










  • In your question: FilterDef name= equalId, but in in @Filter name=equaId (without "l"). Typo?
    – Mark Bramnik
    Jul 24 '18 at 5:25
















I guess doesn't work means your entities get loaded without being filtered here?
– Xtreme Biker
Jul 20 '18 at 6:13




I guess doesn't work means your entities get loaded without being filtered here?
– Xtreme Biker
Jul 20 '18 at 6:13












Yes that's my problem
– lia1812
Jul 20 '18 at 6:14




Yes that's my problem
– lia1812
Jul 20 '18 at 6:14












So you'd better edit the question to be more specific about the issue. Also I guess Spring Boot and Maven have nothing to do here, it's an Hibernate specific.
– Xtreme Biker
Jul 20 '18 at 6:16






So you'd better edit the question to be more specific about the issue. Also I guess Spring Boot and Maven have nothing to do here, it's an Hibernate specific.
– Xtreme Biker
Jul 20 '18 at 6:16






1




1




Thanks for your hint!
– lia1812
Jul 20 '18 at 6:17




Thanks for your hint!
– lia1812
Jul 20 '18 at 6:17












In your question: FilterDef name= equalId, but in in @Filter name=equaId (without "l"). Typo?
– Mark Bramnik
Jul 24 '18 at 5:25




In your question: FilterDef name= equalId, but in in @Filter name=equaId (without "l"). Typo?
– Mark Bramnik
Jul 24 '18 at 5:25












1 Answer
1






active

oldest

votes


















0














So my problem was that I used a jpa session (I didn't know that) instead of hibernate. Now I'm using hibernate and everything is fine and it works :)






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51435699%2fhow-can-i-use-hibernate-annotation-filter-in-spring-boot%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    So my problem was that I used a jpa session (I didn't know that) instead of hibernate. Now I'm using hibernate and everything is fine and it works :)






    share|improve this answer


























      0














      So my problem was that I used a jpa session (I didn't know that) instead of hibernate. Now I'm using hibernate and everything is fine and it works :)






      share|improve this answer
























        0












        0








        0






        So my problem was that I used a jpa session (I didn't know that) instead of hibernate. Now I'm using hibernate and everything is fine and it works :)






        share|improve this answer












        So my problem was that I used a jpa session (I didn't know that) instead of hibernate. Now I'm using hibernate and everything is fine and it works :)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 '18 at 22:22









        lia1812

        61




        61






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51435699%2fhow-can-i-use-hibernate-annotation-filter-in-spring-boot%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            List item for chat from Array inside array React Native

            Thiostrepton

            Caerphilly