mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-21 21:14:12 +08:00
#624727 : fixed getSingleResult() for null usage
This commit is contained in:
parent
8c1c6d6a52
commit
8ea0c87972
@ -9,6 +9,7 @@ import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@ -176,6 +177,12 @@ public abstract class AbstractJPAQuery<Q extends AbstractJPAQuery<Q>> extends HQ
|
||||
logQuery(queryString);
|
||||
Query query = createQuery(queryString, null);
|
||||
reset();
|
||||
return (RT) query.getSingleResult();
|
||||
try{
|
||||
return (RT) query.getSingleResult();
|
||||
}catch(NoResultException e){
|
||||
logger.debug(e.getMessage(),e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package com.mysema.query;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@ -16,6 +17,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -308,5 +310,10 @@ public abstract class AbstractStandardTest {
|
||||
Param<String> name = new Param<String>(String.class,"name");
|
||||
assertEquals("Bob123",query().from(cat).where(cat.name.eq(name)).uniqueResult(cat.name));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void null_as_uniqueResult(){
|
||||
assertNull(query().from(cat).where(cat.name.eq(UUID.randomUUID().toString())).uniqueResult(cat));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user