@@ -0,0 +1,2268 @@
+package com.vladmihalcea.book.hpjp.hibernate.query.escape;%0A%0Aimport com.vladmihalcea.book.hpjp.util.AbstractSQLServerIntegrationTest;%0Aimport com.vladmihalcea.book.hpjp.util.AbstractTest;%0Aimport org.junit.Test;%0A%0Aimport javax.persistence.*;%0Aimport java.util.List;%0A%0Aimport static org.junit.Assert.assertEquals;%0A%0A/**%0A * @author Vlad Mihalcea%0A */%0Apublic class SQLServerEscapeQuestionCharacterTest extends AbstractSQLServerIntegrationTest %7B%0A%0A    @Override%0A    protected Class%3C?%3E%5B%5D entities() %7B%0A        return new Class%3C?%3E%5B%5D %7B%0A            Post.class,%0A        %7D;%0A    %7D%0A%0A    @Test%0A    public void test() %7B%0A        doInJPA(entityManager -%3E %7B%0A            Post post = new Post();%0A            post.setId(1L);%0A            post.setTitle(%22High-Performance Java Persistence%22);%0A            post.setActive(true);%0A%0A            entityManager.persist(post);%0A        %7D);%0A%0A        doInJPA(entityManager -%3E %7B%0A            List%3CPost%3E posts = entityManager%0A            .createQuery(%0A                %22select p %22 +%0A                %22from Post p %22 +%0A                %22where p.active = :active%22, Post.class)%0A            .setParameter(%22active%22, true)%0A            .getResultList();%0A%0A            assertEquals(1, posts.size());%0A        %7D);%0A%0A        doInJPA(entityManager -%3E %7B%0A            List%3CString%3E posts = entityManager%0A            .createNativeQuery(%0A                %22select p.title %22 +%0A                %22from %5Bpost%5D p %22 +%0A                %22where p.%5Bactive%5C%5C?%5D = :active%22)%0A            .setParameter(%22active%22, true)%0A            .getResultList();%0A%0A            assertEquals(1, posts.size());%0A        %7D);%0A    %7D%0A%0A    @Entity(name = %22Post%22)%0A    @Table(name = %22%5Bpost%5D%22)%0A    public static class Post %7B%0A%0A        @Id%0A        private Long id;%0A%0A        private String title;%0A%0A        @Column(name = %22%5Bactive?%5D%22)%0A        private boolean active;%0A%0A        public Long getId() %7B%0A            return id;%0A        %7D%0A%0A        public void setId(Long id) %7B%0A            this.id = id;%0A        %7D%0A%0A        public String getTitle() %7B%0A            return title;%0A        %7D%0A%0A        public void setTitle(String title) %7B%0A            this.title = title;%0A        %7D%0A%0A        public boolean isActive() %7B%0A            return active;%0A        %7D%0A%0A        public void setActive(boolean active) %7B%0A            this.active = active;%0A        %7D%0A    %7D%0A%7D%0A

Add test for escaping illegal character on SQL Server