时间:2010-07-26 17:11:49

标签: gwt jpa gilead

3 个答案:

答案 0 :(得分:1)

我尝试将我的项目设置得非常相似,并且还遇到了hibernate异常。我发现在使用JPA时我需要使用HibernateJPAUtil初始化EntityManagerFactory。当我这样做时,它起作用了。这会将您的前两行代码更改为:

public class MyServiceImpl extends PersistentRemoteService implements MyService {

  public MyServiceImpl() {
    final EntityManagerFactory emf = Persistence.createEntityManagerFactory("MA");    
    final PersistentBeanManager persistentBeanManager = new PersistentBeanManager();
    persistentBeanManager.setPersistenceUtil(new HibernateJpaUtil(emf)); // <- needs EMF here
    persistentBeanManager.setProxyStore(new StatelessProxyStore());
    setBeanManager(persistentBeanManager);
  }

  @Override // from MyService
  public Stuff getStuff() {
    // no need for clone/merge here, as Gilead's GWT PersistentRemoteService does this for us
    ...
    return stuff;
  }
}

我还使用net.sf.gilead.pojo.java5.legacy.LightEntity作为我所有实体的基类(请注意java5.legacy包)。

答案 1 :(得分:0)

实体:

//imports
@Entity
public class Book extends LightEntity implements Serializable {

    private static final long serialVersionUID = 21L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String title;

    @Lob
    private String description;

    @ManyToMany(cascade = CascadeType.ALL)
    private List<Author> author;

    // Getters and setters
    @Override
    public int hashCode() {
       int hash = 0;
       hash += (getId() != null ? getId().hashCode() : 0);
       return hash;
    }

    @Override
    public boolean equals(Object object) {
       // TODO: Warning - this method won't work in the case the id fields are not set
       if (!(object instanceof Book)) {
           return false;
       }
       Course other = (Book) object;
       if ((this.getId() == null && other.getId() != null) || (this.getId() != null && !this.id.equals(other.id))) {
           return false;
       }
       return true;
   }
}

Book对象看起来一样。

然后将其用作服务器上的常规EJB以及客户端上的常规DTO。 不要忘记将Gilead的库添加到项目中。

答案 2 :(得分:0)

希望这篇博客能为您提供帮助。
http://zawoad.blogspot.com/2010/06/google-app-engine-jdo-and-gxtext-gwt.html

这不是你想要的直接例子,但方法应该是这样的。我们使用GWT + JPA + EJB在我们的项目中遵循相同的方法。要通过网络发送您的对象,您需要一个数据传输对象(DTO)。将此DTO转换为Entity对象,并执行您想要执行的任何操作。