Results 1 to 3 of 3

Thread: spring data jpa M2 query findBy did not work for non-id fields

Hybrid View

  1. #1
    Join Date
    May 2009
    Posts
    9

    Default spring data jpa M2 query findBy did not work for non-id fields

    I have a simple application which tries out the spring data jpa M2 release. I have this repository defined:
    public interface fooRepository extends JpaRepository<Foo, String> {
    // query by ID
    List<Foo> findByFooId(String fooId);

    List<Foo> findByRating(String rating);
    }

    the FooId is a @Id field in the domain model, and Rating is a normal field. The first method will always work, but the second one always return 0 rows. Is there anything special about the fields that are not id?
    Spring data jpa did simplify a lot of things, if this query works!
    -much thanks as always-

  2. #2
    Join Date
    Apr 2011
    Posts
    107

    Default

    Hi,

    Could you enable trace to see executed SQL?

    My $.02 is that you try to query a char[x] column and not a varchar column. (you then need to some space to your rating...)

  3. #3
    Join Date
    May 2009
    Posts
    9

    Default

    I saw that the debugging hibernate sql code has something likefor a select statement)

    ... cast(null as date) as from_date, ....

    And the 'date' is not valid for SQL Server, so I manually changed it to 'datetime' and the query worked. So my question is:
    how should I let it (Spring Data) generate 'datetime', and also I see 'joda time' in this project (I didn't start this project), and that is having issues with hibernate 3.6, could this be the reason?

    -thanks

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •