Giter Club home page Giter Club logo

spring-data-mybatis's Introduction


The primary goal of the Spring Data project is to make it easier to build Spring-powered applications that use data access technologies.

This module deals with enhanced support for MyBatis based data access layers. This module does not make any modifications to MyBatis. Non-invasive enhancement of MyBatis functionality by using the pre-compiled MyBatis Mapper Statement mode take developers more flexibility. At the same time, you can use the Spring Data pattern to reduce the amount of code and improve development efficiency.

To put it bluntly, it is to help you automatically generate the Mapper files in advance, all the SQLs are ready, and then, the essence is still MyBatis. Developers who use MyBatis no longer need to envy Spring Data JPA and the like ^_^

Useful Links

Features

  • Do not invade MyBatis, completely native use
  • Use standard Java Persistence API (JPA) annotations
  • Supports full CRUD operations on Entities, as well as more complex queries
  • Support to generate corresponding query by method name in interface (Spring Data)
  • Support associated queries, support automatic identification of associated query conditions
  • Entity base class that provides basic properties
  • Support transparent auditing (such as creation time, last modification)
  • Self-sustained custom writing of MyBatis-based queries, convenient and flexible
  • Easy integration with Spring and Spring Boot
  • Support MySQL, Oracle, SQL Server, H2, PostgreSQL, DB2, Derby, HSQL, Phoenix, MariaDB, Sqlite, Informix, HerdDB, Impala, Clickhouse, CUBRID, EnterpriseDB, Firebird, HANA, Ingres, PolarDB, DM, OSCAR, HighGO, XUGU, Kingbase etc.

Quick Start

Installation

Maven

<dependency>
    <groupId>io.easybest</groupId>
    <artifactId>spring-data-mybatis</artifactId>
    <version>2.1.0</version>
</dependency>

In Spring Boot, use the following starter directly:

<dependency>
    <groupId>io.easybest</groupId>
    <artifactId>spring-data-mybatis-starter</artifactId>
    <version>2.1.0</version>
</dependency>

Gradle

implementation('io.easybest:spring-data-mybatis:2.1.0')

In Spring Boot, use the following starter directly:

implementation('io.easybest:spring-data-mybatis-starter:2.1.0')

Contributing

Here are some ways for you to get involved in the community:

  • GitHub is for social coding: if you want to write code, we encourage contributions through pull requests from forks of this repository.

Getting Help

Here is a reference documentation to help you learn Spring Data Mybatis quickly.

If you have any questions or suggestions, you can record an issue.

In addition, you can also add a QQ group to conduct related discussions and seek some help.

QQ Group 1: 497907039

Donation

paypal

spring-data-mybatis's People

Contributors

easybest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spring-data-mybatis's Issues

Escape character should be added to PGSQL queries

Following #46, It appear the postgresql statement doesn't take care of escape character.

I have created a TEST table with double quote capital case :

CREATE TABLE "TEST" (
  "ID" SERIAL NOT NULL,
  "NAME" varchar(50) DEFAULT NULL,
  PRIMARY KEY ("ID")
);

I have the following error:

 Caused by: org.postgresql.util.PSQLException: ERROR: relation "test" does not exist

If I change from @Table(name = "TEST"). to @Table(name = "\"TEST\""), it work.

If we specify the default name for tables and column using an annotation, it should be automatically escaped.

support async query results

Repository queries can be executed asynchronously using Spring’s asynchronous method execution capability. This means the method will return immediately upon invocation and the actual query execution will occur in a task that has been submitted to a Spring TaskExecutor.

@Async
Future<User> findByFirstname(String firstname);               

@Async
CompletableFuture<User> findOneByFirstname(String firstname); 

@Async
ListenableFuture<User> findOneByLastname(String lastname);    
  1. Use java.util.concurrent.Future as return type.
  2. Use a Java 8 java.util.concurrent.CompletableFuture as return type.
  3. Use a org.springframework.util.concurrent.ListenableFuture as return type.

Wrong ID type Integer requested when creating query like findByEntityId(Long id);

I have to manage to get my @OneToMany with a findBySiteServiceId information and I have found another bug.

This request expect my model constructor to have an ID of type Integer instead of Long as in LongId.java

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: No constructor found in com.domain.security.SiteService matching [java.lang.Integer, java.lang.String, java.lang.String]] with root cause
org.apache.ibatis.executor.ExecutorException: No constructor found in com.domain.security.SiteService matching [java.lang.Integer, java.lang.String, java.lang.String]
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createByConstructorSignature(DefaultResultSetHandler.java:656)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:605)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:578)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:859)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForNestedResultMap(DefaultResultSetHandler.java:831)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:315)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:290)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:187)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)
	at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63)
	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
	at com.sun.proxy.$Proxy95.selectOne(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166)
	at org.springframework.data.mybatis.repository.support.SqlSessionRepositorySupport.selectOne(SqlSessionRepositorySupport.java:85)

I have added on top of my constructor this one so it could start:

	public SiteService(Integer id, String i18nMessageId, String name) {
		super(name, i18nMessageId);
		this.setId(new Long(id));
	}

	public SiteService(String name, String i18nMessageId) {
		super(name, i18nMessageId);
	}

This new constructor looks a bit fancy.

I have then tried to call my private List<SiteService> findBySiteServiceId method, and I have another error regarding constructor:

Caused by: org.apache.ibatis.executor.ExecutorException: No constructor found in com.domain.security.SiteService matching [java.lang.Integer, java.lang.String, java.lang.String, java.lang.Integer, java.lang.String, java.lang.String]
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createByConstructorSignature(DefaultResultSetHandler.java:656)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:605)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:578)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:859)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyNestedResultMappings(DefaultResultSetHandler.java:913)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:868)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForNestedResultMap(DefaultResultSetHandler.java:831)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:315)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:290)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:187)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)

I don't know what are theses extra parameter so I have created the constructor.

This is my schema :

image

These are the values pass to the constructor :

image

It appear that it mix up with my entities, is it my using wrongly the mybatis mapping ?

I have check the example but got nothing.

@OneToMany doesn't select join column because of missing join statement

annotation @OneToMany doesn't join column

It appear the @OneToMany association doesn't work as expected.

version

I am using commit.

This is how I did the join table mapping, in SiteService.java :

@JdbcType(BIGINT)
@OneToMany
@JoinTable(name = "SITE_FUNCTION")
@JoinColumn(name = "SITE_SERVICE_ID")
@NotNull
private List<SiteFunction> siteFunctionList;

Result

Produce an empty array for siteFunctionList

Expected result

Produce an array using database data for siteFunctionList

The select method appear to not add any jointure for this table.

(but @manytoone association seems to work fine so far.)
The xml generated render an empty <sql id="SELECT_CONDITION_INNER"></sql>

What is it use for ?

There is this generated for the mapping by the annotations:

        <collection property="siteFunctionList" ofType="com.domain.security.SiteFunction">
            <id property="id" column="siteFunctionList.id" javaType="java.lang.Long" jdbcType="BIGINT"/>
            <result property="messageId" column="siteFunctionList.messageId" javaType="java.lang.String"
                    jdbcType="VARCHAR"/>
            <result property="name" column="siteFunctionList.name" javaType="java.lang.String" jdbcType="VARCHAR"/>
        </collection>

But nothing for selecting the field.

testing

Dear hatunet,

I have a week or two for testing the module.

I have tried the installation explained in the readme but the project isn't on a repository yet.

I have tried to build the jar with ./mvn install.

I moved the jar in a spring boot boilerplate project in the /lib directory.

I haved tried to import the jar following all of this steps described here : http://stackoverflow.com/questions/20700053/how-to-add-local-jar-file-dependency-to-build-gradle-file

So I am not sure if it's the plugin not working or not finished but adding this doesn't add your classes to my project :

repositories {
    mavenCentral()
    maven { url 'http://repo.spring.io/plugins-release' }
    flatDir {
        dirs 'lib'
    }
}
dependencies {
    compile files('lib/spring-data-mybatis-1.0.1.BUILD-SNAPSHOT-sources.jar')
    compile fileTree(dir: 'lib', include: ['*.jar'])
    compile name: 'spring-data-mybatis-1.0.1.BUILD-SNAPSHOT-sources'
....

Would be happy to test it if you could tell me how you do for testing it.

Add automatic conversion of Boolean to false if null

I know it's not the most important right now but I would like just to open the question

I have a case where I have the following postgresql column :

  "ACTIVE" BOOLEAN NOT NULL DEFAULT TRUE,

In my entity I have

@JdbcType(BOOLEAN)
@Column(name = "ACTIVE")
@NotNull
private Boolean active;

When I try to save this entity, spring-data-mybatis try to insert with null values and it generate an error.

I have annotated the JdbcType so the ORM should be aware of the data type, if active is null it could directly insert false instead of trying to insert a non eligible null.

Bug non mapped attribute request a typeHandler

I have a case where an attribute translateMessage is not stored in the database.

public abstract class I18nId extends LongId implements Cloneable, TranslateMessageInterface {

	private static final Logger logger = LoggerFactory.getLogger(I18nId.class);

	@JdbcType(VARCHAR)
	@Column(name = "I18N_ID")
	@NotNull
	@JsonIgnore
	private String messageId;

	private TranslateMessage translateMessage;

	public String getMessageId() {
		return messageId;
	}

	public void setMessageId(String messageId) {
		this.messageId = messageId;
	}

	public void setTranslateMessage(TranslateMessage translateMessage) {
		this.translateMessage = translateMessage;
	}

	public TranslateMessage getTranslateMessage() {
		if (null == translateMessage) {
			translateMessage = new TranslateMessage(getMessageId(), getDefaultMessage());
		}
		return translateMessage;
	}
}

This will throw the error :

Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalStateException: No typehandler found for property translateMessage
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:120)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:92)
	at org.springframework.data.mybatis.repository.support.MybatisSimpleRepositoryMapperGenerator.generate(MybatisSimpleRepositoryMapperGenerator.java:98)
	... 37 common frames omitted
Caused by: java.lang.IllegalStateException: No typehandler found for property translateMessage
	at org.apache.ibatis.mapping.ResultMapping$Builder.validate(ResultMapping.java:151)
	at org.apache.ibatis.mapping.ResultMapping$Builder.build(ResultMapping.java:140)
	at org.apache.ibatis.builder.MapperBuilderAssistant.buildResultMapping(MapperBuilderAssistant.java:382)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildResultMappingFromContext(XMLMapperBuilder.java:378)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:280)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:252)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements(XMLMapperBuilder.java:244)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:116)
	... 39 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:48342', transport: 'socket'

I fixed it by not creating an attribute and returning a new Instance of TranslateMessage everytime the getter is called.

Better support spring boot with mybatis properties

support configuration:

spring.data.mybatis.mapper-Locations=classpath*:/org/springframework/data/mybatis/samples/mappers/*Mapper.xml
spring.data.mybatis.repositories-base-packages=
spring.data.mybatis.repositories-base-packages-file=
spring.data.mybatis.default-scripting-language=

@RepositoryRestResource vs @Repository

In your updated readme you don't use anymore @EnableMybatisRepository.

I can't remove it because there is two parameter to pass to this annotation : value, mapperLocations.

Only one of these two can be configured by using application.properties, so I have to mix it

spring:
  data:
    mybatis:
      mapper-Locations: classpath*:/mappers/*Mapper.xml
@EnableMybatisRepositories(
	value = "com.repository"
//	mapperLocations = "classpath*:/mappers/*Mapper.xml"
)

Would be nice to move the value somewhere else, that would be useful for testing purpose, so we don't have to copy the configuration.

Also you have replaced the @Repository annotation that expose to spring-data-rest, by this one @RepositoryRestResource.

It work fine but I would like to know the difference between those two.

Question about usage and extends using xml files

Considering the following xml custom mapper for a Manager entity :

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.repository.userManagement.ManagerRepository">
    <!--<cache />-->

    <!-- Is it possible to reuse the spring-data-mybatis instead of writing this one -->
    <resultMap id="managerResultMap" type="com.domain.userManagement.Manager">
        <id property="id" column="id" />
        <result property="login" column="login" jdbcType="VARCHAR" javaType="string" />
        <result property="roleList" column="roleList" jdbcType="BLOB" typeHandler="com.typeHandler.RoleListTypeHandler" />
        <result property="password" column="password" jdbcType="VARCHAR" javaType="string" />
        <result property="version" column="version" jdbcType="BIGINT" javaType="long" />
        <result property="active" column="active" jdbcType="BOOLEAN" javaType="boolean" />
        <result property="creationDateTime" column="creationDateTime" jdbcType="DATE" typeHandler="com.typeHandler.DateTimeTypeHandler" />
        <result property="modificationDateTime" column="modificationDateTime" jdbcType="DATE" typeHandler="com.typeHandler.DateTimeTypeHandler" />
    </resultMap>

    <!-- Is it possible to reuse the spring-data-mybatis instead of writing this one -->
    <sql id="getManagerSelect">
        SELECT
            manager.`ID` as 'id',
            manager.`LOGIN` as 'login',
            manager.`ROLES` as 'roleList',
            manager.`PASSWORD` as 'password',
            manager.`VERSION` as 'version',
            manager.`CREATION_DATETIME` as 'creationDateTime',
            manager.`MODIFICATION_DATETIME` as 'modificationDateTime',
            manager.`ACTIVE` as 'active'
    </sql>

    <!-- Is it possible to reuse the spring-data-mybatis instead of writing this one -->
    <sql id="getManagerFrom">
        FROM
          `MANAGER` manager
    </sql>

    <!-- So it will be possible to write small queries like this -->
    <select id="find" resultType="com.domain.userManagement.Manager" parameterType="Long">
        <include refid="getManagerSelect" />
        <include refid="getManagerFrom" />
        <if test="pk">
          WHERE manager.`ID` = #{pk.value}
        </if>
    </select>
    
    <!-- This is a delete override only for that entity -->
    <delete id="delete" parameterType="com.domain.userManagement.Manager">
        UPDATE
         `MANAGER`
        SET
          `ACTIVE` = 1
        <if test="pk">
          WHERE `ID` = #{pk.value}
        </if>
    </delete>

</mapper>

I would like to know if it is possible to :

  1. override default delete query for a single entity like in this xml
  2. how is it possible to change repository.delete() and repository.deleteAll() for doing it on all entities
  3. reuse the spring-data-mybatis generated resultMap so I don't need to maintain my own (for example by knowing in advance the resultMap id.

Note:

I really wouldn't do that. That would radically change the contract of these two methods but I need to know if these extends can be set up.

how to insert new entity with a fixed id

I need to have something like this do the insertion

this.repository.save(new Entity(1L, 'test'));

The save will fail because it's a new entity and not an update.

I know there is a check on the isNew() method, I just want to know how do you manage these kind of insert properly.

Thanks in advance :)

"Projection type must be an interface"

I have tried to create Projection and exclude some field but I have the following error :

"Projection type must be an interface" 

Could this be related to spring-data-mybatis ?

support query by Example

This chapter will give you an introduction to Query by Example and explain how to use Examples.

Query by Example (QBE) is a user-friendly querying technique with a simple interface. It allows dynamic query creation and does not require to write queries containing field names. In fact, Query by Example does not require to write queries using store-specific query languages at all.

The Query by Example API consists of three parts:

  • Probe: That is the actual example of a domain object with populated fields.

  • ExampleMatcher: The ExampleMatcher carries details on how to match particular fields. It can be reused across multiple Examples.

  • Example: An Example consists of the probe and the ExampleMatcher. It is used to create the query.

Query by Example is suited for several use-cases but also comes with limitations:

When to use

Querying your data store with a set of static or dynamic constraints

Frequent refactoring of the domain objects without worrying about breaking existing queries

Works independently from the underlying data store API

Limitations

  • Query predicates are combined using the AND keyword

  • No support for nested/grouped property constraints like firstname = ?0 or (firstname = ?1 and lastname = ?2)

  • Only supports starts/contains/ends/regex matching for strings and exact matching for other property types

Before getting started with Query by Example, you need to have a domain object. To get started, simply create an interface for your repository:

public class Person {

  @Id
  private String id;
  private String firstname;
  private String lastname;
  private Address address;

  // … getters and setters omitted
}

This is a simple domain object. You can use it to create an Example. By default, fields having null values are ignored, and strings are matched using the store specific defaults. Examples can be built by either using the of factory method or by using ExampleMatcher. Example is immutable.

Person person = new Person();                         
person.setFirstname("Dave");                          

Example<Person> example = Example.of(person);         
  1. Create a new instance of the domain object
  2. Set the properties to query
  3. Create the Example

Examples are ideally be executed with repositories. To do so, let your repository interface extend QueryByExampleExecutor. Here’s an excerpt from the QueryByExampleExecutor interface:

public interface QueryByExampleExecutor<T> {

  <S extends T> S findOne(Example<S> example);

  <S extends T> Iterable<S> findAll(Example<S> example);

  // … more functionality omitted.
}

Case where repository.save doesn't save, is there a way to log queries

I have a case where I call the method save of the repository, and I have no insertion at all, neither errors.

This is my model :

@Entity(table = "oauth_client_details")
public class OAuthClient implements ClientDetails {

	public static final String GRANT_TYPE_AUTHORIZATION_CODE = "authorization_code";
	public static final String GRANT_TYPE_REFRESH_TOKEN = "refresh_token";

	public static final String SCOPE_READ = "read";
	public static final String SCOPE_WRITE = "write";
	public static final String SCOPE_TRUST = "trust";

	@Id
	@JdbcType(VARCHAR)
	@Column(name = "client_id")
	private String clientId;

	@JdbcType(VARCHAR)
	@Column(name = "resource_ids")
	@TypeHandler(CommaSeparatedTypeHandler.class)
	@NotNull
	private List<String> resourceIdList;

	@JdbcType(VARCHAR)
	@Column(name = "scope")
	@TypeHandler(CommaSeparatedTypeHandler.class)
	@NotNull
	private List<String> scopeList;

	@JdbcType(VARCHAR)
	@Column(name = "client_secret")
	@NotNull
	private String clientSecret;

	@JdbcType(VARCHAR)
	@Column(name = "authorized_grant_types")
	@TypeHandler(CommaSeparatedTypeHandler.class)
	@NotNull
	private List<String> authorizedGrantTypeList;

	@JdbcType(VARCHAR)
	@Column(name = "web_server_redirect_uri")
	@TypeHandler(CommaSeparatedTypeHandler.class)
	@NotNull
	private List<String> registeredRedirectUriList;

	@JdbcType(VARCHAR)
	@Column(name = "authorities")
	@TypeHandler(RoleListTypeHandler.class)
	@NotNull
	private List<Role> roleList;

	@JdbcType(INTEGER)
	@Column(name = "access_token_validity")
	@NotNull
	private Integer accessTokenValiditySeconds;


	@JdbcType(INTEGER)
	@Column(name = "refresh_token_validity")
	@NotNull
	private Integer refreshTokenValiditySeconds;

	@JdbcType(VARCHAR)
	@Column(name = "additional_information")
	@TypeHandler(JsonMapTypeHandler.class)
	private Map<String, Object> additionalInformationMap;

	@JdbcType(VARCHAR)
	@Column(name = "autoapprove")
	private Boolean isAutoApprove;

	@Override
	public String getClientId() {
		return clientId;
	}

	public void setClientId(String clientId) {
		this.clientId = clientId;
	}


	public void setClientSecret(String clientSecret) {
		this.clientSecret = clientSecret;
	}


	public List<Role> getRoleList() {
		return roleList;
	}

	public void setRoleList(List<Role> roleList) {
		this.roleList = roleList;
	}


	public void setAccessTokenValiditySeconds(Integer accessTokenValiditySeconds) {
		this.accessTokenValiditySeconds = accessTokenValiditySeconds;
	}


	public void setRefreshTokenValiditySeconds(Integer refreshTokenValiditySeconds) {
		this.refreshTokenValiditySeconds = refreshTokenValiditySeconds;
	}

	public Map<String, Object> getAdditionalInformationMap() {
		return additionalInformationMap;
	}

	public void setAdditionalInformationMap(Map<String, Object> additionalInformationMap) {
		this.additionalInformationMap = additionalInformationMap;
	}


	public Boolean getAutoApprove() {
		return isAutoApprove;
	}

	public void setAutoApprove(Boolean autoApprove) {
		isAutoApprove = autoApprove;
	}


	public List<String> getScopeList() {
		return scopeList;
	}

	public void setScopeList(List<String> scopeList) {
		this.scopeList = scopeList;
	}

	public List<String> getAuthorizedGrantTypeList() {
		return authorizedGrantTypeList;
	}

	public void setAuthorizedGrantTypeList(List<String> authorizedGrantTypeList) {
		this.authorizedGrantTypeList = authorizedGrantTypeList;
	}

	public List<String> getRegisteredRedirectUriList() {
		return registeredRedirectUriList;
	}

	public void setRegisteredRedirectUriList(List<String> registeredRedirectUriList) {
		this.registeredRedirectUriList = registeredRedirectUriList;
	}

	public List<String> getResourceIdList() {
		return resourceIdList;
	}

	public void setResourceIdList(List<String> resourceIdList) {
		this.resourceIdList = resourceIdList;
	}

	@Override
	public Set<String> getResourceIds() {
		return new HashSet<>(getResourceIdList());
	}

	@Override
	public Set<String> getScope() {
		return new HashSet<>(getScopeList());
	}

	@Override
	public String getClientSecret() {
		return clientSecret;
	}

	@Override
	public Integer getRefreshTokenValiditySeconds() {
		return refreshTokenValiditySeconds;
	}

	@Override
	public Integer getAccessTokenValiditySeconds() {
		return accessTokenValiditySeconds;
	}

	@Override
	public Set<String> getAuthorizedGrantTypes() {
		return new HashSet<>(getAuthorizedGrantTypeList());
	}


	@Override
	public Set<String> getRegisteredRedirectUri() {
		return new HashSet<>(getRegisteredRedirectUriList());
	}

	@Override
	public Map<String, Object> getAdditionalInformation() {
		return getAdditionalInformationMap();
	}

	@Override
	public boolean isAutoApprove(String scope) {
		return getAutoApprove();
	}

	@Override
	public boolean isSecretRequired() {
		return true;
	}

	@Override
	public boolean isScoped() {
		return true;
	}


	@Override
	public Collection<GrantedAuthority> getAuthorities() {
		List<Role> roleList = getRoleList();
		List<GrantedAuthority> authorities = new ArrayList<>(roleList.size());

		for (Role role : roleList) {
			authorities.add(
					new SimpleGrantedAuthority(role.toString())
			);
		}

		return authorities;
	}
}

This is how I save the model in my DatabaseLoader.java

OAuthClient clientOauth = new OAuthClient();
clientOauth.setClientId("bo");
clientOauth.setClientSecret("123456");

ArrayList<String> authorizedGrandTypeList = new ArrayList<>();
authorizedGrandTypeList.add(OAuthClient.GRANT_TYPE_AUTHORIZATION_CODE);
authorizedGrandTypeList.add(OAuthClient.GRANT_TYPE_REFRESH_TOKEN);
clientOauth.setAuthorizedGrantTypeList(authorizedGrandTypeList);

ArrayList<Role> roleList = new ArrayList<>();
roleList.add(Role.ROLE_CLIENT);
clientOauth.setRoleList(roleList);

ArrayList<String> scopeList = new ArrayList<>();
scopeList.add(OAuthClient.SCOPE_READ);
scopeList.add(OAuthClient.SCOPE_WRITE);
scopeList.add(OAuthClient.SCOPE_TRUST);
clientOauth.setScopeList(scopeList);

clientOauth.setAccessTokenValiditySeconds(1800);
clientOauth.setRefreshTokenValiditySeconds(3600);

clientOauth.setAutoApprove(true);

ArrayList<String> registeredRedirectUriList = new ArrayList<>();
registeredRedirectUriList.add("http://localhost:8080");
registeredRedirectUriList.add("http://dev:31735");

clientOauth.setRegisteredRedirectUriList(registeredRedirectUriList);

HashMap<String, Object> additionalInformationMap = new HashMap<>();
additionalInformationMap.put("companyId", "1");
additionalInformationMap.put("companyName", "toto");
clientOauth.setAdditionalInformationMap(additionalInformationMap);

ArrayList<String> resourceIdList = new ArrayList<>();
resourceIdList.add(ResourceServerConfig.RESOURCE_ID);
clientOauth.setResourceIdList(resourceIdList);

this.oAuthClientRepository.save(clientOauth);

TypeHandlers:

@MappedJdbcTypes(JdbcType.VARCHAR)
@MappedTypes(List.class)
public class CommaSeparatedTypeHandler extends BaseTypeHandler<List<Object>> {

	@Override
	public void setNonNullParameter(PreparedStatement ps, int i, List<Object> list, JdbcType jdbcType) throws SQLException {
		ps.setString(i, StringUtils.collectionToDelimitedString(list, UniqueStore.COMMA_DELIMITER));
	}

	@Override
	public List<Object> getNullableResult(ResultSet rs, String columnName) throws SQLException {
		String resultString = rs.getString(columnName);
		return getFromResultString(resultString);
	}

	@Override
	public List<Object> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
		return getFromResultString(rs.getString(columnIndex));
	}

	@Override
	public List<Object> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
		return getFromResultString(cs.getString(columnIndex));
	}

	private List<Object> getFromResultString(String result) {
		ArrayList<Object> list = new ArrayList<>();
		for (Object item : result.split(UniqueStore.COMMA_DELIMITER)) {
			list.add(item);
		}

		return list;
	}
}
@MappedJdbcTypes(JdbcType.VARCHAR)
@MappedTypes(Map.class)
public class JsonMapTypeHandler extends BaseTypeHandler<Map<String, Object>> {

	private Gson gson = new Gson();

	@Override
	public void setNonNullParameter(PreparedStatement ps, int i, Map<String, Object> map, JdbcType jdbcType) throws SQLException {
		ps.setString(i, gson.toJson(map));
	}

	@Override
	public Map<String, Object> getNullableResult(ResultSet rs, String columnName) throws SQLException {
		String resultString = rs.getString(columnName);
		return getFromResultString(resultString);
	}

	@Override
	public Map<String, Object> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
		return getFromResultString(rs.getString(columnIndex));
	}

	@Override
	public Map<String, Object> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
		return getFromResultString(cs.getString(columnIndex));
	}

	private Map<String, Object> getFromResultString(String result) {
		Map map = gson.fromJson(result, Map.class);
		return map;
	}
}

I'm still debugging the issue with a poor set of tools, do you know how I could activate the log queries ?

Support Instant for @CreatedDate and @LastModifiedDate

I was trying to setup my database for theses annotations and

    Caused by: java.lang.IllegalArgumentException: now we can not support java.time.Instant for org.springframework.data.annotation.CreatedDate

It sounds like the library still uses the old date apis when there are better replacements available (310).

I did the following annotations

@CreatedDate
@NotNull
@JdbcType(TIMESTAMP)
@Column(name = "CREATION_DATETIME")
private Instant creationDateTime;

I could use timestamp jdbcType and Date so it will probably work, but date is not the best options.

Ideally we would use Instant (java) and timestamp (jdbcType) as in my example.

The way it is made force us to use Date :

https://github.com/hatunet/spring-data-mybatis/blob/3c24082f923d758dbb0da4382f9adc09854ea871/src/main/java/org/springframework/data/mybatis/repository/support/MybatisMetamodelEntityInformation.java#L98

DateTime is a joda class. they support that. but 310 replaces joda, though even in joda, Instant, not DateTime, is the right type.

It's probably the spring-data spec, I fixed it using getter and setter using Instant, but it would be nice to also support Instant as java type.

MariaDB configuration

It seems that 1.0.1 Release doesn't work with MariaDB :

        2016-12-05 15:06:38.258  INFO 1624 --- [           main] o.s.j.d.DriverManagerDataSource          : Loaded JDBC driver: org.mariadb.jdbc.Driver
2016-12-05 15:07:39.585  WARN 1624 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'application': Unsatisfied dependency expressed through field 'managerRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'managerRepository': Cannot resolve reference to bean 'sqlSessionFactory_Localism' while setting bean property 'localism'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory_Localism': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: not support database id: null
2016-12-05 15:07:39.588  INFO 1624 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat
2016-12-05 15:07:39.610 ERROR 1624 --- [           main] o.s.boot.SpringApplication               : Error handling failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataV1DataSourceConfig' defined in file [/workspace/school.domain.com/dka/spring-data-mybatis-test-project/build/classes/main/com/config/DataV1DataSourceConfig.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataV1DataSourceSettings' defined in file [/workspace/school.domain.com/dka/spring-data-mybatis-test-project/build/classes/main/com/config/DataV1DataSourceSettings.class]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2f40e5db has not been refreshed yet
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1128) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1022) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.java:228) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:185) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:383) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:337) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.boot.context.event.EventPublishingRunListener.finished(EventPublishingRunListener.java:93) ~[spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
	at org.springframework.boot.SpringApplicationRunListeners.callFinishedListener(SpringApplicationRunListeners.java:79) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
	at org.springframework.boot.SpringApplicationRunListeners.finished(SpringApplicationRunListeners.java:72) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
	at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:813) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
	at com.Application.main(Application.java:20) [main/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataV1DataSourceSettings' defined in file [/workspace/school.domain.com/dka/spring-data-mybatis-test-project/build/classes/main/com/config/DataV1DataSourceSettings.class]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2f40e5db has not been refreshed yet
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:207) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$ShortcutDependencyDescriptor.resolveShortcut(AutowiredAnnotationBeanPostProcessor.java:744) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1070) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1059) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.resolvedCachedArgument(AutowiredAnnotationBeanPostProcessor.java:552) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.access$200(AutowiredAnnotationBeanPostProcessor.java:117) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:581) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:370) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1219) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:551) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	... 27 common frames omitted
Caused by: java.lang.IllegalStateException: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2f40e5db has not been refreshed yet
	at org.springframework.context.support.AbstractApplicationContext.assertBeanFactoryActive(AbstractApplicationContext.java:1068) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.context.support.GenericApplicationContext.getAutowireCapableBeanFactory(GenericApplicationContext.java:305) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:275) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor$LocalValidatorFactory.run(ConfigurationPropertiesBindingPostProcessor.java:453) ~[spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
	at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.getValidator(ConfigurationPropertiesBindingPostProcessor.java:387) ~[spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
	at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.determineValidator(ConfigurationPropertiesBindingPostProcessor.java:370) ~[spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
	at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:332) ~[spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
	at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:303) ~[spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1575) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	... 43 common frames omitted

2016-12-05 15:07:39.615 ERROR 1624 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'application': Unsatisfied dependency expressed through field 'managerRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'managerRepository': Cannot resolve reference to bean 'sqlSessionFactory_Localism' while setting bean property 'localism'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory_Localism': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: not support database id: null
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:592) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:370) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1219) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:551) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:754) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
	at com.Application.main(Application.java:20) [main/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'managerRepository': Cannot resolve reference to bean 'sqlSessionFactory_Localism' while setting bean property 'localism'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory_Localism': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: not support database id: null
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1486) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1231) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:551) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:207) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1131) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1059) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:589) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	... 19 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory_Localism': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: not support database id: null
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	... 32 common frames omitted
Caused by: java.lang.IllegalArgumentException: not support database id: null
	at org.springframework.data.mybatis.repository.localism.LocalismFactoryBean.getLocalism(LocalismFactoryBean.java:77) ~[spring-data-mybatis-1.0.1.RELEASE.jar:na]
	at org.springframework.data.mybatis.repository.localism.LocalismFactoryBean.afterPropertiesSet(LocalismFactoryBean.java:57) ~[spring-data-mybatis-1.0.1.RELEASE.jar:na]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
	... 39 common frames omitted

Disconnected from the target VM, address: '127.0.0.1:47934', transport: 'socket'

Process finished with exit code 1

it fails on this line

    String databaseId = sqlSessionFactory.getConfiguration().getDatabaseId();

getDatabaseId is null, is this because I am using this something else than H2 ?

1.0.3 Test broken

From a clone repository
Running

 mvn install

Results :

Failed tests:
RoleSimpleRepositoryTests.testCount:135 expected:<4> but was:<5>
RoleSimpleRepositoryTests.testFindAll:114 expected:<4> but was:<5>
RoleSimpleRepositoryTests.testFindByPage:184 expected:<4> but was:<5>
RoleSimpleRepositoryTests.testFindBySort:175 expected:<ROLE_assistant> but was:<ROLE_admin>

I did a small Pull requests here : #24

source

Hi, I am currently trying to work on a spring-data-mybatis module as well very actively (everyday).

I am trying to make the jclagache plugin compatible with the latest spring version but it's a bit painful to got it work.

I've seen you've just created this 4 days ago ? Do you mind if we work together ?

support limiting query

should support like

User findFirstByOrderByLastnameAsc();

User findTopByOrderByAgeDesc();

Page<User> queryFirst10ByLastname(String lastname, Pageable pageable);

Slice<User> findTop3ByLastname(String lastname, Pageable pageable);

List<User> findFirst10ByLastname(String lastname, Sort sort);

List<User> findTop10ByLastname(String lastname, Pageable pageable);

query.

support distinct query

should support like

List<User> findDistinctUserByLastnameOrFirstname(String lastname, String firstname);

query.

support delete query

should support like

  Long deleteByLastname(String lastname);

  List<User> removeByLastname(String lastname);

query.

findByModel doesn't work as expected

findByAttribute doesn't work as expected.

I have tried to create a simple method in my interface to produce the effect of @OneToMany in a query that I could use (see : #84)

version

Commit f22774e0a6a9057e5909caeba9a2cde55038227a

This is my repository :

public interface SiteFunctionRepository extends CrudRepository<SiteFunction, Long> {
	List<SiteFunction> findBySiteService(SiteService siteService);
}

The method is called in the getter of SiteService.java

	public List<SiteFunction> getSiteFunctionList() {
		if (null != this.getId() && null == siteFunctionList) {
			siteFunctionList = siteFunctionRepository.findBySiteService(this);
		}
		return siteFunctionList;
	}

I have a the following error :

Stopping service Tomcat
Error handling failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myBatisConfig' defined in file [/workspace/git.kopaxgroup.com/kopaxgroup/api/build/classes/main/com/common/config/MyBatisConfig.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataV1DataSourceConfig' defined in file [/workspace/git.kopaxgroup.com/kopaxgroup/api/build/classes/main/com/common/config/DataV1DataSourceConfig.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataV1DataSourceSettings' defined in file [/workspace/git.kopaxgroup.com/kopaxgroup/api/build/classes/main/com/common/config/DataV1DataSourceSettings.class]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@616fe72b has not been refreshed yet
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:563)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1134)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1028)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.java:228)
	at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:185)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:383)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:337)
	at org.springframework.boot.context.event.EventPublishingRunListener.finished(EventPublishingRunListener.java:93)
	at org.springframework.boot.SpringApplicationRunListeners.callFinishedListener(SpringApplicationRunListeners.java:79)
	at org.springframework.boot.SpringApplicationRunListeners.finished(SpringApplicationRunListeners.java:72)
	at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:813)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
	at com.Application.main(Application.java:49)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataV1DataSourceConfig' defined in file [/workspace/git.kopaxgroup.com/kopaxgroup/api/build/classes/main/com/common/config/DataV1DataSourceConfig.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataV1DataSourceSettings' defined in file [/workspace/git.kopaxgroup.com/kopaxgroup/api/build/classes/main/com/common/config/DataV1DataSourceSettings.class]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@616fe72b has not been refreshed yet
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:563)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:207)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$ShortcutDependencyDescriptor.resolveShortcut(AutowiredAnnotationBeanPostProcessor.java:740)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1075)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1064)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.resolvedCachedArgument(AutowiredAnnotationBeanPostProcessor.java:548)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.access$200(AutowiredAnnotationBeanPostProcessor.java:117)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:577)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1225)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:552)
	... 27 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataV1DataSourceSettings' defined in file [/workspace/git.kopaxgroup.com/kopaxgroup/api/build/classes/main/com/common/config/DataV1DataSourceSettings.class]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@616fe72b has not been refreshed yet
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:563)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:207)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$ShortcutDependencyDescriptor.resolveShortcut(AutowiredAnnotationBeanPostProcessor.java:740)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1075)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1064)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.resolvedCachedArgument(AutowiredAnnotationBeanPostProcessor.java:548)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.access$200(AutowiredAnnotationBeanPostProcessor.java:117)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:577)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1225)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:552)
	... 43 common frames omitted
Caused by: java.lang.IllegalStateException: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@616fe72b has not been refreshed yet
	at org.springframework.context.support.AbstractApplicationContext.assertBeanFactoryActive(AbstractApplicationContext.java:1068)
	at org.springframework.context.support.GenericApplicationContext.getAutowireCapableBeanFactory(GenericApplicationContext.java:307)
	at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:275)
	at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor$LocalValidatorFactory.run(ConfigurationPropertiesBindingPostProcessor.java:453)
	at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.getValidator(ConfigurationPropertiesBindingPostProcessor.java:387)
	at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.determineValidator(ConfigurationPropertiesBindingPostProcessor.java:370)
	at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:332)
	at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:303)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1581)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:554)
	... 59 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:46008', transport: 'socket'
Application startup failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'databaseLoader' defined in file [/workspace/git.kopaxgroup.com/kopaxgroup/api/build/classes/main/com/common/config/DatabaseLoader.class]: Unsatisfied dependency expressed through constructor parameter 4; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'siteFunctionRepository': Invocation of init method failed; nested exception is org.springframework.data.mybatis.repository.support.MybatisQueryException: can not find property: siteService from entity: com.domain.security.SiteService
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1154)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1056)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
	at com.Application.main(Application.java:49)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'siteFunctionRepository': Invocation of init method failed; nested exception is org.springframework.data.mybatis.repository.support.MybatisQueryException: can not find property: siteService from entity: com.domain.security.SiteService
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1589)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:554)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:207)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1136)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1064)
	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
	... 19 common frames omitted
Caused by: org.springframework.data.mybatis.repository.support.MybatisQueryException: can not find property: siteService from entity: com.domain.security.SiteService
	at org.springframework.data.mybatis.repository.query.PartTreeMybatisQuery.buildQueryCondition(PartTreeMybatisQuery.java:131)
	at org.springframework.data.mybatis.repository.query.PartTreeMybatisQuery.doCreateSelectQueryStatement(PartTreeMybatisQuery.java:234)
	at org.springframework.data.mybatis.repository.query.PartTreeMybatisQuery.doCreateCollectionQueryStatement(PartTreeMybatisQuery.java:249)
	at org.springframework.data.mybatis.repository.query.PartTreeMybatisQuery.doCreateQueryStatement(PartTreeMybatisQuery.java:268)
	at org.springframework.data.mybatis.repository.query.PartTreeMybatisQuery.<init>(PartTreeMybatisQuery.java:85)
	at org.springframework.data.mybatis.repository.query.MybatisQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(MybatisQueryLookupStrategy.java:71)
	at org.springframework.data.mybatis.repository.query.MybatisQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(MybatisQueryLookupStrategy.java:120)
	at org.springframework.data.mybatis.repository.query.MybatisQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(MybatisQueryLookupStrategy.java:50)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:435)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:220)
	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:280)
	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:266)
	at org.springframework.data.mybatis.repository.support.MybatisRepositoryFactoryBean.afterPropertiesSet(MybatisRepositoryFactoryBean.java:55)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1648)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1585)
	... 30 common frames omitted

Process finished with exit code 1

it seems that buildQueryCondition is crashing in PartTreeMybatisQuery.

Null

I have the following error

Caused by: org.springframework.jdbc.BadSqlGrammarException: Error selecting key or setting result to parameter object. Cause: org.postgresql.util.PSQLException: ERROR: relation "MANAGER_id_seq" does not exist

Closed, it appear it's because I am using ID uppercase column name so I can't use LongId as it is

Annotation bug due to missing comma in MybatisSimpleRepositoryMapperGenerator

I have an error in org.apache.ibatis.builder.SqlSourceBuilder at L101

builder.jdbcType(resolveJdbcType(value));

My model annotation looks like :

@JdbcType(VARCHAR)
@Column(name = "authorized_grant_types")
@TypeHandler(CommaSeparatedTypeHandler.class)
private List<String> authorizedGrantTypeList;

The value of value is incorrect.

Result:

authorizedGrantTypeList,jdbcType=VARCHARtypeHandler=com.typeHandler.CommaSeparatedTypeHandler

Expected:

authorizedGrantTypeList,jdbcType=VARCHAR,typeHandler=com.typeHandler.CommaSeparatedTypeHandler

I think the error comes from that line because of the missing ,

Log

Application startup failed
java.lang.IllegalStateException: Failed to execute CommandLineRunner
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:803)
	at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:784)
	at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:771)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
	at com.Application.main(Application.java:48)
Caused by: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error resolving JdbcType. Cause: java.lang.IllegalArgumentException: No enum constant org.apache.ibatis.type.JdbcType.VARCHARtypeHandler=com.typeHandler.CommaSeparatedTypeHandler
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:79)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447)
	at com.sun.proxy.$Proxy79.update(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:295)
	at org.springframework.data.mybatis.repository.support.SqlSessionRepositorySupport.update(SqlSessionRepositorySupport.java:109)
	at org.springframework.data.mybatis.repository.support.SimpleMybatisRepository.save(SimpleMybatisRepository.java:86)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:503)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:488)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
	at com.sun.proxy.$Proxy114.save(Unknown Source)
	at com.common.config.DatabaseLoader.run(DatabaseLoader.java:141)
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:800)
	... 6 common frames omitted
Caused by: org.apache.ibatis.builder.BuilderException: Error resolving JdbcType. Cause: java.lang.IllegalArgumentException: No enum constant org.apache.ibatis.type.JdbcType.VARCHARtypeHandler=com.typeHandler.CommaSeparatedTypeHandler
	at org.apache.ibatis.builder.BaseBuilder.resolveJdbcType(BaseBuilder.java:73)
	at org.apache.ibatis.builder.SqlSourceBuilder$ParameterMappingTokenHandler.buildParameterMapping(SqlSourceBuilder.java:101)
	at org.apache.ibatis.builder.SqlSourceBuilder$ParameterMappingTokenHandler.handleToken(SqlSourceBuilder.java:67)
	at org.apache.ibatis.parsing.GenericTokenParser.parse(GenericTokenParser.java:69)
	at org.apache.ibatis.builder.SqlSourceBuilder.parse(SqlSourceBuilder.java:45)
	at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:44)
	at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:292)
	at org.apache.ibatis.executor.statement.BaseStatementHandler.<init>(BaseStatementHandler.java:64)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.<init>(PreparedStatementHandler.java:40)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.<init>(RoutingStatementHandler.java:46)
	at org.apache.ibatis.session.Configuration.newStatementHandler(Configuration.java:530)
	at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:48)
	at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
	at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434)
	... 32 common frames omitted
Caused by: java.lang.IllegalArgumentException: No enum constant org.apache.ibatis.type.JdbcType.VARCHARtypeHandler=com.typeHandler.CommaSeparatedTypeHandler
	at java.lang.Enum.valueOf(Enum.java:238)
	at org.apache.ibatis.type.JdbcType.valueOf(JdbcType.java:25)
	at org.apache.ibatis.builder.BaseBuilder.resolveJdbcType(BaseBuilder.java:71)
	... 51 common frames omitted
Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5d8bafa9: startup date [Sat Dec 10 20:08:36 ICT 2016]; root of context hierarchy
Unregistering JMX-exposed beans on shutdown
Disconnected from the target VM, address: '127.0.0.1:59426', transport: 'socket'

Process finished with exit code 1

PagedQuery support MS Sql Server

when query like

Page<User> findByLastnameOrderByLastnameAsc(String lastname, Pageable pageable);

should support MS SqlServer.

Supported spring-data annotations by this plugin

Can I assume these spring-data annotations work well with this plugins ?

  • @Version : Should add ETAG to response header using specified @column, should be incremented on update.
  • @CreatedDate : Should update with current timestamp when inserting
  • @LastModifiedDate : Should update with current timestamp when updating
  • @createdby : Should update with principal when inserting
  • @LastModifiedBy : Should update with principal when updating

Edit

So far I have tested

with success:

with failure:

  • @Version: correctly add etag to response header but does not be incremented on insert neither update

When I try to access the data rest controller with an entity created without a setVersion(1)

/rest/companies/1 reached end of additional filter chain; proceeding with original chain
null
java.lang.NullPointerException: null
	at org.springframework.data.rest.webmvc.support.ETag.getVersionInformation(ETag.java:192)
	at org.springframework.data.rest.webmvc.support.ETag.from(ETag.java:76)
  • @CreatedDate : Doesn't update the datetime
  • @LastModifiedDate : Doesn't update the datetime

todo test:

  • @LastModifiedBy : Should update with principal when updating
  • @createdby : Should update with principal when inserting

spring-data-rest-base-path ignored to investigate

By anychance, I have created this question on stackoverflow :

http://stackoverflow.com/questions/41054470/is-there-another-way-to-set-spring-data-rest-base-path-than-properties-which-are

I really don't know if it's related to your plugin, when I was trying to set this property in a sandbox it was working fine.

But with a stack using all this dependencies, it get mapped to my application context /

Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@52851b44: startup date [Fri Dec 09 13:32:25 ICT 2016]; root of context hierarchy
Mapped "{[/ || ],methods=[GET],produces=[application/hal+json || application/json || application/*+json;charset=UTF-8]}" onto public org.springframework.http.HttpEntity<org.springframework.data.rest.webmvc.RepositoryLinksResource> org.springframework.data.rest.webmvc.RepositoryController.listRepositories()
Mapped "{[/ || ],methods=[OPTIONS],produces=[application/hal+json || application/json || application/*+json;charset=UTF-8]}" onto public org.springframework.http.HttpEntity<?> org.springframework.data.rest.webmvc.RepositoryController.optionsForRepositories()
Mapped "{[/ || ],methods=[HEAD],produces=[application/hal+json || application/json || application/*+json;charset=UTF-8]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.data.rest.webmvc.RepositoryController.headForRepositories()
Mapped "{[/{repository}],methods=[HEAD],produces=[application/hal+json || application/json || application/*+json;charset=UTF-8]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.data.rest.webmvc.RepositoryEntityController.headCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable) throws org.springframework.web.HttpRequestMethodNotSupportedException
Mapped "{[/{repository}],methods=[GET],produces=[application/hal+json || application/json || application/*+json;charset=UTF-8]}" onto public org.springframework.hateoas.Resources<?> org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException
Mapped "{[/{repository}],methods=[OPTIONS],produces=[application/hal+json || application/json || application/*+json;charset=UTF-8]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.data.rest.webmvc.RepositoryEntityController.optionsForCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation)
Mapped "{[/{repository}],methods=[GET],produces=[application/x-spring-data-compact+json || text/uri-list]}" onto public org.springframework.hateoas.Resources<?> org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResourceCompact(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException
Mapped "{[/{repository}],methods=[POST],produces=[application/hal+json || application/json || application/*+json;charset=UTF-8]}" onto public org.springframework.http.ResponseEntity<org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryEntityController.postCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.PersistentEntityResource,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler,java.lang.String) throws org.springframework.web.HttpRequestMethodNotSupportedException

instead of my sandbox

Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2a448449: startup date [Fri Dec 09 13:14:01 ICT 2016]; root of context hierarchy
Mapped "{[/api/ || /api],methods=[HEAD],produces=[application/hal+json || application/json || application/*+json;charset=UTF-8]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.data.rest.webmvc.RepositoryController.headForRepositories()
Mapped "{[/api/ || /api],methods=[OPTIONS],produces=[application/hal+json || application/json || application/*+json;charset=UTF-8]}" onto public org.springframework.http.HttpEntity<?> org.springframework.data.rest.webmvc.RepositoryController.optionsForRepositories()
Mapped "{[/api/ || /api],methods=[GET],produces=[application/hal+json || application/json || application/*+json;charset=UTF-8]}" onto public org.springframework.http.HttpEntity<org.springframework.data.rest.webmvc.RepositoryLinksResource> org.springframework.data.rest.webmvc.RepositoryController.listRepositories()
Mapped "{[/api/{repository}],methods=[OPTIONS],produces=[application/hal+json || application/json || application/*+json;charset=UTF-8]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.data.rest.webmvc.RepositoryEntityController.optionsForCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation)
Mapped "{[/api/{repository}],methods=[HEAD],produces=[application/hal+json || application/json || application/*+json;charset=UTF-8]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.data.rest.webmvc.RepositoryEntityController.headCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable) throws org.springframework.web.HttpRequestMethodNotSupportedException

I wonder if it's because of incompatibility with my dependencies

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar']) // <== spring-data-mybatis
    compile('com.google.code.gson:gson:2.7')
    compile('org.apache.commons:commons-lang3:3.4')
    compile("org.apache.directory.server:apacheds-server-jndi:1.5.5")
    compile("joda-time:joda-time")
    compile('com.fasterxml.jackson.datatype:jackson-datatype-joda:2.8.1')
    compile("org.mariadb.jdbc:mariadb-java-client:1.5.2")
    compile("org.mybatis:mybatis:3.4.1")
    compile("org.mybatis:mybatis-spring:1.3.0")
    compile("org.mybatis.spring.boot:mybatis-spring-boot-starter:1.1.1")
    compile('org.flywaydb:flyway-core:4.0.3')
    compile('org.springframework.session:spring-session-jdbc:1.2.2.RELEASE')
    compile('javax.servlet:jstl:1.2')
    compile('org.apache.tomcat.embed:tomcat-embed-jasper:9.0.0.M10')
    compile("org.springframework.boot:spring-boot-starter-security")
    compile("org.springframework.security:spring-security-config")
    compile('org.springframework.security.oauth:spring-security-oauth2:2.0.11.RELEASE')
    testCompile("org.springframework.security:spring-security-test")
    compile('org.springframework.security:spring-security-jwt:1.0.5.RELEASE')
    compile("org.springframework.boot:spring-boot-starter-cache")
    compile("org.springframework.boot:spring-boot-starter-mail")
    compile("org.springframework.boot:spring-boot-starter-web")
    compile('org.springframework.boot:spring-boot-starter-data-rest')
    testCompile("org.springframework.boot:spring-boot-starter-test")
    optional("org.springframework.boot:spring-boot-configuration-processor")
    optional('org.springframework.boot:spring-boot-devtools')
    compile('pl.project13.maven:git-commit-id-plugin:2.2.1')
}

You seems experienced in spring-data, by any chance, do you know if it could be related to your plugin or other plugin and do you know another way to fix the spring.data.rest.base-path ?

TypeHandler are ignored by spring-data-mybatis

MANAGER.ROLES columns looks like 1,2,3

Each ID represent a Role.

Role is an ENUM class.

I have a typeHandler to retrieve and set my roles but it seems ignored by spring-data-mybatis

package com.typeHandler;

import com.domain.Role;
import com.common.store.UniqueStore;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class RoleListTypeHandler<E extends Enum<Role>> extends BaseTypeHandler<List<Role>> {

	@Override
	public void setNonNullParameter(PreparedStatement ps, int i, List<Role> roleList, JdbcType jdbcType) throws SQLException {
		ArrayList<String> roles = new ArrayList<>();
		for (Role role: roleList){
			String roleId = String.valueOf(role.getValue());
			// add role only if not already present
			if( !roles.contains(roleId) )
			{
				roles.add(roleId);
			}
		}
		ps.setString(i, StringUtils.join(roles, UniqueStore.COMMA_DELIMITER));
	}

	@Override
	public List<Role> getNullableResult(ResultSet rs, String columnName) throws SQLException {
		String roles = rs.getString(columnName);
		return getRoleListFromResultString(roles);
	}

	@Override
	public List<Role> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
		return getRoleListFromResultString(rs.getString(columnIndex));
	}

	@Override
	public List<Role> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
		return getRoleListFromResultString(cs.getString(columnIndex));
	}

	private List<Role> getRoleListFromResultString(String result)
	{
		ArrayList<Role> roleList = new ArrayList();
		List<String> roles = Arrays.asList(result.split("\\s*,\\s*"));

		for (String role : roles)
		{
			roleList.add( Role.getRoleFromValue(Integer.parseInt(role)) );
		}
		return roleList;
	}
}

And this is my class Role.java :

public enum Role {

	ROLE_USER(1),
	ROLE_MANAGER(2),
	ROLE_ADMIN(3),
	ROLE_CLIENT(4),
	ROLE_TRUSTED_CLIENT(5);

	private int value;

	Role(final int value) {
		this.value = value;
	}

	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		this.value = value;
	}

	/**
	 * From int to Role
	 *
	 * @param value
	 * @return
	 */
	public static Role getRoleFromValue(int value) {
		Role result = null;
		for (Role s : Role.values()) {
			if (s.getValue() == value) {
				result = s;
			}
		}
		if (result == null) {
			throw new IllegalArgumentException("No exist the Role with that value");
		}
		return result;
	}
}

My Mybatis mapper has the following resultMap :

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.repository.ManagerRepository">
    <!--<cache />-->

    <resultMap id="managerResultMap" type="com.domain.Manager">
        <id property="id" column="id"/>
        <result property="login" column="login"/>
        <result property="roleList" column="roleList" typeHandler="com.typeHandler.RoleListTypeHandler" />
    </resultMap>


    <sql id="getManagerSelect">
        SELECT
            manager.`ID` as 'id',
            manager.`LOGIN` as 'login'
            manager.`ROLES` as 'roleList'
    </sql>

    <sql id="getManagerFrom">
        FROM
          `MANAGER` manager
    </sql>

    <select id="count" resultType="java.lang.Long" parameterType="Integer">
        SELECT COUNT(ID)
        <include refid="getManagerFrom"/>
    </select>

    <select id="exists" resultType="java.lang.Boolean" parameterType="Integer">
        SELECT COUNT(ID)
        <include refid="getManagerFrom"/>
        WHERE
        ID = #{id};
    </select>


    <select id="find" resultMap="managerResultMap" parameterType="Integer">
        <include refid="getManagerSelect"/>
        <include refid="getManagerFrom"/>
        <if test="pk">
            WHERE manager.`ID` = #{pk.value}
        </if>
    </select>
</mapper>

I have added this to my configuration

@Bean
public SqlSessionFactoryBean sqlSessionFactory() throws Exception {
	final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
	sessionFactory.setDataSource(dataSource());
	sessionFactory.setTypeHandlers(new TypeHandler[] {
		new DateTimeTypeHandler(),
		new RoleListTypeHandler()
	});
	sessionFactory.setTypeAliases(new Class[] {
		DateTime.class,
		Role.class,
		Manager.class,
	});
	return sessionFactory;
}

A call to the method findByLogin of my `ManagerRepository.java`

```java
public interface ManagerRepository extends PagingAndSortingRepository<Manager, Long> {
	public Manager findByLogin(String login);
}

Result in an error in SqlSessionTemplate throwed in SqlSessionInterceptor.

### Error querying database.  Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'roleList' from result set.  Cause: java.lang.IllegalArgumentException: No enum constant com.domain.Role.2
### The error may exist in com.domain.Manager.findByLogina932691fd7d64c599c77cfe05cc71f4d_auto_generate.xml
### The error may involve com.domain.Manager.findByLogina932691fd7d64c599c77cfe05cc71f4d
### The error occurred while handling results
### SQL: select `manager`.id as `id`,`manager`.login as `login`,`manager`.password as `password`,`manager`.role_list as `roleList` from manager `manager`  where   (  `manager`.login=? )
### Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'roleList' from result set.  Cause: java.lang.IllegalArgumentException: No enum constant com.domain.Role.2

I have no idea how to fix this and why this is happening in the first place.

This type handler was storing and retrieving Role correctly without installing spring-data-mybatis so I guess it comes from the 1.0.3.

Do you know what's going wrong ?

How to extend xml with custom mappers

My goal was to add a findAll alias method in order to see and repair the broken query of @OneToMany (see #84)

I have added the following mapper in my mapper directory :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.domain.security.SiteService">
    <select id="getAll" resultType="com.domain.security.SiteService" lang="XML">
        select
        "siteService"."ID" as "id",
        "siteService"."I18N_ID" as "messageId",
        "siteService"."NAME" as "name" from "SITE_SERVICE" "siteService"
        <if test="_condition != null">
            <trim prefix=" where " prefixOverrides="and |or "></trim>
        </if>
        <if test="_ids != null">where "siteService"."ID" in
            <foreach item="item" index="index" collection="_ids" open="(" separator="," close=")">#{item}</foreach>
        </if>
        <if test="_sorts != null">
            <bind name="_columnsMap"
                  value='#{"id":"\"siteService\".\"ID\"","messageId":"\"siteService\".\"I18N_ID\"","name":"\"siteService\".\"NAME\""}'/>
            order by
            <foreach item="item" index="idx" collection="_sorts" open="" separator="," close=""><if
                    test="item.ignoreCase">lower(</if>${_columnsMap[item.property]}
                <if test="item.ignoreCase">)</if>
                ${item.direction}
            </foreach>
        </if>
    </select>
</mapper>

It's a copy of the generated mapper of SiteServiceRepository.java.

I have just change the resultMap with a resultType and renamed the id="findAll" to id="getAll"

I can't change the resultMap because it has been defined before by spring-data-mybatis.

I expect to extend the original xml for that class.

This is what my repository :

@RepositoryRestResource(collectionResourceRel = "siteServices", path = HttpPathStore.REPO_PATH_SITE_SERVICES)
public interface SiteServiceRepository extends CrudRepository<SiteService, Long> {

	List<SiteService> findAll();

	List<SiteService> getAll();
}

I have the following error

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property getAll found for type SiteService!
	at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77)
	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329)
	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309)
	at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272)
	at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243)
	at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76)
	at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:235)
	at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:373)
	at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:353)
	at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:84)
	at org.springframework.data.mybatis.repository.query.PartTreeMybatisQuery.<init>(PartTreeMybatisQuery.java:79)
	at org.springframework.data.mybatis.repository.query.MybatisQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(MybatisQueryLookupStrategy.java:71)
	at ....

I would like to know if I am expecting correctly and if this is a bug.

I suppose I can't use original mybatis service in parallel of spring-data-mybatis.

I would like to know how I could extend the generated mybatis with my custom queries and handler.

peer dependencies 1.0.8

I have tried to clone the latest version of spring-data-mybatis on branch master

My application failed with this error :

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
Application failed to start due to an exception
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.lang.Class<org.springframework.data.repository.Repository<?, ?>>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

I have upgraded in my build.gradle :

compile("org.mybatis.spring.boot:mybatis-spring-boot-starter:1.2.0")
compile("org.mybatis:mybatis:3.4.2")
compile("org.mybatis:mybatis-spring:1.3.1")

I manage to do a working build with these dependencies using this commit

What version are you exactly compatible with in next release ?

I have encoutered some trouble (#85) with @Projection annotation. This is why I am trying to upgrade.

support streaming query results

The results of query methods can be processed incrementally by using a Java 8 Stream as return type. Instead of simply wrapping the query results in a Stream data store specific methods are used to perform the streaming.

Stream the result of a query with Java 8 Stream

Stream<User> findAllByCustomQueryAndStream();

Stream<User> readAllByFirstnameNotNull();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.