tags:

views:

46

answers:

2

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

Thanks

A: 

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.

Maksim
A: 

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

}
bovo
This doesn't seem to work. I got a HibernateException. Any help is greatly appreciated.
bovo