Question

Can someone please provide me an example of GWT + JPA + Gilead, I can't seem to find anything on Google with this topic.

Thanks


Thanks Maksim,

I'm not using this in an EJB server but Tomcat. I understand the step you've pointed out above but not sure on how to do the next step which is to set up PersistentBeanManager and send my object over the wire.

Here is what I have thus far but I haven't got a chance to test if this works yet. If you see a problem with this let me know, thanks.

private HibernateJpaUtil gileadUtil = new HibernateJpaUtil();

private static final EntityManagerFactory factory = Persistence.createEntityManagerFactory("MyPersistentUnit");

public MyServlet() {

    gileadUtil.setEntityManagerFactory(factory);

    PersistentBeanManager pbm = new PersistentBeanManager();
    pbm.setPersistenceUtil(gileadUtil);
    pbm.setProxyStore(new StatelessProxyStore());

    setBeanManager(pbm);

    Book book = new Book();
    Book cloned = (Book) pbm.clone(book);               

            //send the cloned book over the wire

}

No correct solution

OTHER TIPS

I tried to set up my project very similar and also ran into the hibernate exception. I figured out that when using JPA I need to initialize the HibernateJPAUtil with the EntityManagerFactory. When I did this it worked. This changes your first two lines of code to:

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;
  }
}

Also I used net.sf.gilead.pojo.java5.legacy.LightEntity as base class for all my entities (note the java5.legacy package).

Entity:

//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;
   }
}

The Book object looks same.

Then use it as regular EJB on your server and as regular DTO's on your client. Don't forget to add Gilead's libraries to your project.

Hope this blog will help you.
http://zawoad.blogspot.com/2010/06/google-app-engine-jdo-and-gxtext-gwt.html

This is not a direct a example of what you want but the approach should be like this. We followed the same approach in our project with GWT+JPA+EJB. to send your object over the wire you need a Data Transfer Object (DTO). Convert this DTO to Entity object and do whatever you want to do.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top