@@ -0,0 +1,2032 @@
+package com.vladmihalcea.book.hpjp.hibernate.identifier;%0A%0Aimport com.vladmihalcea.book.hpjp.util.AbstractSQLServerIntegrationTest;%0Aimport org.hibernate.Session;%0Aimport org.hibernate.jdbc.Work;%0Aimport org.junit.Test;%0A%0Aimport javax.persistence.*;%0Aimport java.sql.Connection;%0Aimport java.sql.PreparedStatement;%0Aimport java.sql.ResultSet;%0Aimport java.sql.SQLException;%0Aimport java.util.concurrent.atomic.AtomicLong;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertNotNull;%0A%0A/**%0A * %3Ccode%3ESQLServerScopeIdentity%3C/code%3E - SQLServerScopeIdentity%0A *%0A * @author Vlad Mihalcea%0A */%0Apublic class SQLServerScopeIdentity 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 testScopeIdentity() %7B%0A        doInJPA(entityManager -%3E %7B%0A            Session session = entityManager.unwrap(Session.class);%0A            final AtomicLong resultHolder = new AtomicLong();%0A            session.doWork(connection -%3E %7B%0A                try(PreparedStatement statement = connection.prepareStatement(%22INSERT INTO post VALUES (?) select scope_identity() %22) ) %7B%0A                    statement.setString(1, %22abc%22);%0A                    if ( !statement.execute() ) %7B%0A                        while ( !statement.getMoreResults() && statement.getUpdateCount() != -1 ) %7B%0A                            // do nothing until we hit the resultset%0A                        %7D%0A                    %7D%0A                    try (ResultSet rs = statement.getResultSet()) %7B%0A                        if(rs.next()) %7B%0A                            resultHolder.set(rs.getLong(1));%0A                        %7D%0A                    %7D%0A                %7D%0A            %7D);%0A            assertNotNull(resultHolder.get());%0A        %7D);%0A    %7D%0A%0A    @Entity(name = %22Post%22)%0A    public static class Post %7B%0A%0A        @Id%0A        @GeneratedValue(strategy = GenerationType.IDENTITY)%0A        private Long id;%0A%0A        private String name;%0A    %7D%0A%7D%0A

Add test for scope_identity()