IT

MariaDB 필드의 성배에 값이 있지만 null을 가져왔습니다.

itgroup 2023. 10. 5. 21:32
반응형

MariaDB 필드의 성배에 값이 있지만 null을 가져왔습니다.

제가 이해할 수 없는 이상한 문제를 겪고 있습니다.Job 객체를 생성하여 MariaDB에 저장합니다.개체에 저장하는 "userName" 필드가 있습니다.마리아 DB의 HeidiSQL 패널에서 값이 성공적으로 설정된 것을 확인할 수 있습니다.그러나 Job.findById(jobId)에 의해 userName= null인 Job 개체가 반환됩니다.

class Job {
    String userName;    
    public Job(String name){
        userName=name;
        init();//initiate some transient fields that are omitted here
        //println "Job is initiated "+this.id;
    }
    static mapping={
        id generator:"identity"
    }
    static constraints = {
        //userName(blank:true,nullable:true);
    }
}

Job 개체는 JobController에 의해 생성되고 지속됩니다.

class JobController {

static scaffolding=true;
public static Job initiateJob(String name){
    Job job=new Job(name)

    job.save(flush:true);
    if(job.hasErrors())
        println job.errors;
    println "New job initiated "+job.id+": "+job.userName;
    return job;
}
//I use the jobId to keep track of the job in session
public static Job trackJob(String jobId){
    Long l=Long.parseLong(jobId);
    Job job=Job.find("from Job as j where j.id=:id",[id:l]);//**The job object has userName=null!**
    //Job job=Job.findById(l);//**This doesn't work either**
    if(job==null){
        println "Job is not found. Need to check the error.";

    }
    return job;
}
} 

너무 헷갈리네요.DB를 직접 확인하면 userName 열이 있는 행이 보이므로 행이 실제로 지속된다고 생각합니다.저의 솔직한 논리가 무엇이 잘못되었는지 잘 모르겠습니다.성배 2.4.4를 사용하고 있습니다.이 작업 컨트롤러의 범위는 싱글톤입니다.

도와주셔서 감사합니다!

편집: 다음을 시도했는데 예상치 못한 결과가 나왔습니다.

def jobList=Job.findAll("from Job as j where j.userName is not null");
println jobList.size()+" "+jobList;

결과는 다음과 같습니다.1 [Job: id:1 user name:null]

null이 아닌 결과가 userName= null인 항목을 반환하는 이유를 이해할 수 없습니다.제가 저지른 실수가 뭔가요?

언급URL : https://stackoverflow.com/questions/34351325/grails-on-mariadb-field-has-value-but-fetched-null

반응형