เกณฑ์ไฮเบอร์เนตไม่ทำงานใน SQLite

เกียร์ของฉัน:

คลาสเอนทิตีของฉันเรียบง่าย

@Entity
@Table(name = "RegistrationRequests")
public class RegistrationRequest {

    @Id
    @GeneratedValue
    Integer id;
    String uuid;
    ... getters and setters ...
}

uuid ถูกกำหนดให้กับ UUID.randomUUID().toString() และคงอยู่ในฐานข้อมูลอย่างถูกต้อง ตอนนี้ปัญหาคือเมื่อฉันพยายามดึงคำขอที่เก็บไว้จากฐานข้อมูลโดยใช้ Hibernate Criteria

   Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RegistrationRequest.class);
    criteria.add(Restrictions.eq("uuid", '\'' + uuid + '\''));
    List requests = criteria.list();

ให้ผลลัพธ์ที่ว่างเปล่าเสมอ แต่ถ้าฉันรัน SQL ที่สร้างขึ้น

select
        this_.id as id2_0_,
        this_.created as created2_0_,
        this_.email as email2_0_,
        this_.isVerified as isVerified2_0_,
        this_.name as name2_0_,
        this_.password as password2_0_,
        this_.surname as surname2_0_,
        this_.uuid as uuid2_0_ 
    from
        RegistrationRequests this_ 
    where
        this_.uuid='ced61d13-f5a7-4c7e-a047-dd6f066d8e67'

ผลลัพธ์ถูกต้อง (นั่นคือหนึ่งบันทึกถูกเลือกจากฐานข้อมูล)

ฉันรู้สึกงุนงง พยายามทุกอย่างแต่ก็ไม่เป็นผล...


person Bolek Tekielski    schedule 15.04.2012    source แหล่งที่มา
comment
'\'' + uuid + '\'' ดูแปลกๆ จะเกิดอะไรขึ้นถ้าคุณใช้ uuid โดยไม่มี ' arround the uuid?   -  person andih    schedule 15.04.2012


คำตอบ (1)


คุณไม่จำเป็นต้องตั้งค่าส่วนคำสั่งwhere ด้วยตัวเองเท่าที่ฉันทราบเกี่ยวกับ hibernate api (ฉันใช้ Nhibernate) ดังนั้นเมื่อคุณตั้งค่าส่วนคำสั่งของคุณเป็น 'myValue' คุณกำลังค้นหาสตริงเพื่อให้ตรงกับ 'myValue' โดยที่ ตามที่คุณต้องการ o ค้นหา myValue

หวังว่าการเปลี่ยนแปลงนี้น่าจะทำให้มันใช้งานได้:

Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RegistrationRequest.class);
    criteria.add(Restrictions.eq("uuid", uuid));
    List requests = criteria.list();
person Baz1nga    schedule 15.04.2012
comment
นั่นไม่ได้ช่วยอะไรมากนัก เนื่องจาก SQLite ไม่สามารถจัดการกับข้อความค้นหาที่มียัติภังค์ได้ ดังนั้นฉันจึงต้องอ้างอิงพารามิเตอร์ โดยไม่มีเครื่องหมายคำพูด SQLite บ่น: ข้อผิดพลาด: โทเค็นที่ไม่รู้จัก: 4c7e - person Bolek Tekielski; 16.04.2012
comment
ข้อความค้นหาที่ถูกสร้างขึ้นเมื่อคุณมีข้อความค้นหาตามเกณฑ์ข้างต้นคืออะไร - person Baz1nga; 16.04.2012
comment
ข้อความค้นหานั้นเหมือนกับในโพสต์ของฉันทุกประการ โดยไม่มีเครื่องหมายคำพูดล้อมรอบ uuid เท่านั้น เมื่อฉันพยายามรันคำสั่งนี้ ฉันได้รับ SQLIte บ่นเกี่ยวกับโทเค็นที่ไม่รู้จัก ฉันคิดว่านี่อาจเป็นปัญหาเฉพาะของ SQLite ... - person Bolek Tekielski; 17.04.2012