2011-10-03 3 views
1

웹 사이트를 만들려고 GAE 및 GWT를 사용하고 있으며 처음으로 JDO를 db로 사용하려고합니다. 그러나 db에 객체를 추가 할 때 오류가 발생하지 않습니다. 동일한 객체를 검색하려고 시도 할 때만 인스턴스화되지 않은 null 객체 만 검색합니다. 따라서 개체 User를 만들고 사용자 전자 메일을 기반으로 저장할 경우 전자 메일을 기반으로 동일한 사용자를 검색하려고하면 모든 필드가 null로 설정된 사용자 개체가 생성됩니다.JDO 영구 필드가 반환됩니다. null

JDO 관리자 클래스 :

package com.sixpac.website.server; 

import java.util.ArrayList; 
import java.util.LinkedHashMap; 
import java.util.List; 
import java.util.Map; 
import java.util.Collections; 

import javax.jdo.JDOHelper; 
import javax.jdo.PersistenceManager; 
import javax.jdo.PersistenceManagerFactory; 

import com.sixpac.website.client.User; 

public class UserManager implements UserInterface 
{ 
    private static final PersistenceManagerFactory pmfInstance = JDOHelper.getPersistenceManagerFactory("transactions-optional") ; 

    /** 
    * create and return an instance of the persistence manager 
    * @return 
    */ 
    public static PersistenceManagerFactory getPersistenceManagerFactory() 
    { 
     return pmfInstance ; 
    } 


    public void addUser(User user) 
    { 
     PersistenceManager pm = getPersistenceManagerFactory().getPersistenceManager() ; 

     System.out.println("in addUser manager: " + user.getEmail() + ":" + user.getPassword() + ":" + user.getFName() + ":" + user.getLName()) ; 

     try 
     { 
      pm.currentTransaction().begin() ; 
      pm.makePersistent(user) ; 
      pm.currentTransaction().commit() ; 
     } 
     catch(Exception e) 
     { 
      pm.currentTransaction().rollback() ; 
      System.out.println("addUser: " + e) ; 
//   throw new RuntimeException(e) ; 
     } 
     finally 
     { 
      pm.close() ; 
     } 
    } 

    public void removeUser(String email) 
    { 
     PersistenceManager pm = getPersistenceManagerFactory().getPersistenceManager() ; 

     User user ; 

     try 
     { 
      pm.currentTransaction().begin() ; 
      user = pm.getObjectById(User.class, email) ; 
      pm.deletePersistent(user) ; 
      pm.currentTransaction().commit() ; 
     } 
     catch(Exception e) 
     { 
      pm.currentTransaction().rollback() ; 
      System.out.println("removeUser: " + e) ; 
//   throw new RuntimeException(e) ; 
     } 
     finally 
     { 
      pm.close() ; 
     } 
    } 

    public void updateUser(String email, int state) 
    { 
     PersistenceManager pm = getPersistenceManagerFactory().getPersistenceManager() ; 

     User user ; 

     try 
     { 
      pm.currentTransaction().begin() ; 
      user = pm.getObjectById(User.class, email) ; 
      user.setState(state) ; 

      pm.makePersistent(user) ; 
      pm.currentTransaction().commit() ; 
     } 
     catch(Exception e) 
     { 
      pm.currentTransaction().rollback() ; 
      System.out.println("updateUser: " + e) ; 
//   throw new RuntimeException(e) ; 
     } 
     finally 
     { 
      pm.close() ; 
     } 
    } 

    public User getUser(String email) 
    { 
     PersistenceManager pm = getPersistenceManagerFactory().getPersistenceManager() ; 

     System.out.println("in getUser manager: " + email) ; 

     User user = new User() ; 
     try 
     { 
      pm.currentTransaction().begin() ; 
      user = pm.getObjectById(User.class, email) ; 
      pm.currentTransaction().commit() ; 
     } 
     catch(Exception e) 
     { 
      pm.currentTransaction().rollback() ; 
//   throw new RuntimeException(e) ; 
     } 
     finally 
     { 
      pm.close() ; 
     } 

     return user ; 
    } 

    public List<User> listUser() 
    { 
     PersistenceManager pm = getPersistenceManagerFactory().getPersistenceManager() ; 
     String query = "select from " + User.class.getName() ; 
     return (List<User>) pm.newQuery(query).execute() ; 
    } 
} 

직렬화 구현하는 사용자 클래스 :

package com.sixpac.website.client; 

import java.io.Serializable; 
import javax.jdo.annotations.IdGeneratorStrategy; 
import javax.jdo.annotations.IdentityType; 
import javax.jdo.annotations.PersistenceCapable; 
import javax.jdo.annotations.Persistent; 
import javax.jdo.annotations.PrimaryKey; 

@PersistenceCapable(identityType = IdentityType.APPLICATION) 
public class User implements Serializable 
{ 
    private static final long ID = 1L ; 

    @PrimaryKey 
    @Persistent 
    private String email ; 
    @Persistent 
    private String fname ; 
    @Persistent 
    private String lname ; 
    @Persistent 
    private String psswrd ; 
    @Persistent 
    private String inst ; 
    @Persistent 
    private String details ; 
    @Persistent 
    private int state ; 

    public User() 
    { 
     email = null ; 
     fname = null ; 
     lname = null ; 
     psswrd = null ; 
     inst = null ; 
     details = null ; 
     state = 0 ; 
    } 

    public User(String email, String psswrd, String fname, String lname, String inst, String details) 
    { 
     this.psswrd = psswrd ; 
     this.fname = fname ; 
     this.lname = lname ; 
     this.email = email ; 
     this.inst = inst ; 
     this.details = details ; 
     state = 0 ; 
    } 

    public String getFName() 
    { 
     return fname ; 
    } 
    public void setFName(String fname) 
    { 
     this.fname = fname ; 
    } 

    public String getLName() 
    { 
     return lname ; 
    } 
    public void setLName(String lname) 
    { 
     this.lname = lname ; 
    } 

    public String getPassword() 
    { 
     return psswrd ; 
    } 
    public void setPassword(String psswrd) 
    { 
     this.psswrd = psswrd ; 
    } 

    public String getEmail() 
    { 
     return email ; 
    } 
    public void setEmail(String email) 
    { 
     this.email = email ; 
    } 

    public String getInstetute() 
    { 
     return inst ; 
    } 
    public void setInstetute(String inst) 
    { 
     this.inst = inst ; 
    } 

    public String getDetails() 
    { 
     return details ; 
    } 
    public void setDetails(String details) 
    { 
     this.details = details ; 
    } 

    public int getState() 
    { 
     return state ; 
    } 
    public void setState(int state) 
    { 
     this.state = state ; 
    } 
} 

내가 주시면 감사하겠습니다 잘못하고있는 무슨에 어떤 생각!

감사합니다.

+0

내가 어떤 수정없이 내 환경에서 코드를 실행했다, 당신이 언급 한 기능을 (/ 쿼리를 추가) 벌금을 작동 밝혀졌습니다. 프로덕션 또는 로컬에서 문제가 발생합니까? 값이 저장되는지 여부를 데이터 저장소에서 확인 했습니까? 명확히하십시오. –

답변

관련 문제