0

For development purposes i'm using a windows environment (Eclipse / Jboss) There i have a userDAO, that offers the method to rerieve a UserEntity by first- and lastname. This Query runs well on the dev environment. However on the Unix-Environment, i get a javax.persistence.NoResultException: No entity found for query Exception.

Situation in Detail: A REST-Service is beeing called, containing many Data, along with a firstname and lastname. this parameters needs to be used to obtain the actuall userEntity. (It fails for ANY user on Unix.)

So, the rest service is doing this:

@Consumes("application/json")
@Produces("application/json")
public String create(String plaindata) {

JSONObject data = new JSONObject(plaindata);

String ownerFirstname = data.getString("userFirstname"); //Yes userX, not ownerX

String ownerLastname = data.getString("userLastname");

UserEntity owner = null;
    try {
        owner = userDataService.getUserDetailsByName(ownerFirstname, ownerLastname);
    } catch (Exception e) {
        throw new Exception("Found zero possible users for the given name '" + ownerFirstname + " " + ownerLastname
                + "'. Cannot invoke process.", e);
    }
...
}

The userDataService looks (stripped) like this:

private static String GET_USER_BY_FIRSTNAME_LASTNAME_QUERY = "SELECT * FROM " + DBConstants.USER_TABLE_NAME 
        + " user WHERE user.FIRST_NAME = :firstnameValue AND user.LAST_NAME = :lastnameValue";

public UserEntity getUserDetailsByName(String firstname, String lastname) {
    Query query = em.createNativeQuery(GET_USER_BY_FIRSTNAME_LASTNAME_QUERY, UserEntity.class);

    query.setParameter("firstnameValue", firstname);
    query.setParameter("lastnameValue", lastname);

    UserEntity u =  (UserEntity) query.getSingleResult();
    return u;
}

DBConstants contains the table name like:

public static final String DATATABLE_PREFIX = "pre_";
public static final String USER_TABLE_NAME = DATATABLE_PREFIX+"user_entity";

Column Names in mySQL are Capitalized, so everything seems right.

this works on a Windows Environment, but NOT in the Unix Environment :(

dognose
  • 20,360
  • 9
  • 61
  • 107
  • 1
    Is your production database empty, where your dev one isn't? http://stackoverflow.com/q/4848776/139010 – Matt Ball Mar 02 '13 at 17:58
  • 3
    so that begs the question ... WHY are you using SQL queries when JPQL would likely suffice, and be datastore-independent ? – DataNucleus Mar 02 '13 at 17:58
  • @MattBall: Nope, it isnt. – dognose Mar 02 '13 at 18:00
  • @DataNucleus: I didn't design the DAOs :) - Beside of that: The complete application is working, so the DAOs seem fine. Just combined with data from the REST-POST-Request it fails. – dognose Mar 02 '13 at 18:01

1 Answers1

0
String ownerFirstname = data.getString("userFirstname").trim(); 
String ownerLastname = data.getString("userLastname").trim();

And it works... Strange thing - what could be the difference between windows and unix towards this issue? (The Exception logged absolutely NO Whitespace)

dognose
  • 20,360
  • 9
  • 61
  • 107