Hi guys, how integrate hibernate with vaadin, any have an easy example? CRUD?—
Thanks.
Hi guys, how integrate hibernate with vaadin, any have an easy example? CRUD?—
Thanks.
Hi,
First, pro tips:
Examples:
cheers,
matti
Hi Matti, can you see my code, is well , but i need test it for a pro of vaddin…
Hi,
I’m sorry but I can’t find all the time to help each and every Vaadin users, especially with private project, there are too many.
If your project is open source, share it here (or preferably in github and share link here) and
maybe
you can make me or somebody else interested enough to quickly help you with your project. But I guess it would need to be somehow special to gain the interest among community. Otherwise, I strongly suggest to hire one of our experts for a project kickstart. This is really typical business for us and one of the ways how we finance large part the development of Vaadin: our expert checks out your code and the project structure and gives his/hers valueble insights - and customers are typically very happy to get started on the right foot.
cheers,
matti
Hi Matti,
Because you comment to me to stay away from JPAContainer?..
bye.
I think the DAO as follows :
…
[code]
public void crear(Usuario c){
SessionFactory sf=null;
Session sesion=null;
Transaction tx=null;
try{
sf=HibernateUtil.getSessionFactory();
sesion=sf.openSession();
tx=sesion.beginTransaction();
sesion.save(c);
tx.commit();
sesion.close();
}catch(Exception ex){
}
}
public void editar(Usuario c){
SessionFactory sf=null;
Session sesion=null;
Transaction tx=null;
try{
sf=HibernateUtil.getSessionFactory();
sesion=sf.openSession();
tx=sesion.beginTransaction();
sesion.update(c);
tx.commit();
sesion.close();
}catch(Exception ex){
}
}
public List buscarPorNombre(String nombre){
SessionFactory sf=HibernateUtil.getSessionFactory();
Session sesion=sf.openSession();
Query consultaSQL=sesion.createQuery("from Usuario where nombre='"+nombre+"'");
List<Usuario> lista=consultaSQL.list();
return lista;
}
public List buscarPorId(int id){
SessionFactory sf=HibernateUtil.getSessionFactory();
Session sesion=sf.openSession();
Query consultaSQL=sesion.createQuery("from Usuario where id='"+id+"'");
List<Usuario> lista=consultaSQL.list();
return lista;
}
public void eliminar(Usuario c){
SessionFactory sf=null;
Session sesion=null;
Transaction tx=null;
try{
sf=HibernateUtil.getSessionFactory();
sesion=sf.openSession();
tx=sesion.beginTransaction();
sesion.delete(c);
tx.commit();
sesion.close();
}catch(Exception ex){
}
}
public List mostrarTodo(){
SessionFactory sf=HibernateUtil.getSessionFactory();
Session sesion=sf.openSession();
Query consultaSQL=sesion.createQuery("from Usuario");
List<Usuario> lista=consultaSQL.list();
return lista;
}
[/code]…
And to fill my table I get the following:
tabla.addContainerProperty(“nombre”, String.class, null);
tabla.addContainerProperty(“apepat”, String.class, null);
tabla.addContainerProperty(“apemat”, String.class, null);
tabla.addContainerProperty(“fono”, String.class, null);
tabla.addContainerProperty(“celular”, String.class, null);
tabla.addContainerProperty(“estado”, String.class, null);
UsuarioDAO cDAO = new UsuarioDAO();
List<Usuario> c = cDAO.mostrarTodo();
for (int i = 0; i < c.size(); i++) {
Item item = tabla.addItem(c.get(i).getId());
item.getItemProperty("nombre").setValue(c.get(i).getNombre());
item.getItemProperty("apepat").setValue(c.get(i).getApepat());
item.getItemProperty("apemat").setValue(c.get(i).getApemat());
item.getItemProperty("fono").setValue(c.get(i).getFono());
item.getItemProperty("celular").setValue(c.get(i).getCelular());
item.getItemProperty("estado").setValue(c.get(i).getEstado());
}
Hi,
Here is is some discussion why
you should
not
use JPAContainer
. In summary: without it is easier, better performing and you have more control on what really happens at the persisstency layer. Also the JPA access code is less bound with Vaadin code, so it might be reusable if you for example happen to publish a REST endpoints for third party apps.
Instead of using the default indexed container, and copying properties from pojos to Vaadin Properties, as you have done, it is much easier if you use BeanItemContainer or MTable from Viritin (then you don’t need to think about containers at all, just plain).
With Viritin binding the data to table would be something like:
MTable<Usuario> myListing = new MTable<>().setBeans(cDAO.mostrarTodo());
With BeanItemContainer:
Table t = new Table();
BeanItemContainer bic = new BeanItemContainer<Usario>(Usario.class, cDAO.mostrarTodo());
t.setContainerDataSource(bic);
Wrote the example codes right into the forum so they may contain typos.
cheers,
matti
Matti:
Impressive is the speed of loading data into the grid now .
i use this:(ONLY 2 SECOND 598 elements in my table)
UsuarioDAO cDAO=new UsuarioDAO();
BeanItemContainer bic = new BeanItemContainer(Usuario.class, cDAO.mostrarTodo());
tabla.setContainerDataSource(bic);
and with mi original code 7 second.
Thanks
What if I have 80,000 records i do not need the table will automatically load default ?
You should try Viritin, its ListContainer (replacement for BeanItemContainer, used behind the scenes) is much much better performing.
But finally you’ll have to start limiting the query sizes, your DB (connection) just wont scale to many thousands of records. E.g. just return top 100 results from your query and display those. Or make a “lazy binding” to your Table, for example like in
this example
using MTable from Viritin. It is bit simpler if you don’t need sorting, then you can use
this constructor
.
cheers,
matti
Perfect bone I define myself by default show only 100 items , now that if I’m using FilterTable to find and I just loaded 100 and seek an element that is out of those 100 , it found ?
thanks
because I have something like what I leave in the attached image
thanks.
Help plz
I have never used FilterTable so I don’t know how well it handles “lazyloading”, other than via the Container interface.
I’d implement the search functionality above the table separately, that would then control what kind of listings are displayed by the table. In the Grid you can place an arbitrary components to header cells, so you can do that kind of UI easier (with quality databinding).
cheers,
matti
Hi,
The easiest way for you, I believe, is to use a full stack framework, which alreday handshaked Vaadin and ORM and provide functionality to generate CRUD. Have a look at
CUBA platform
, which implements all that having tight integration of Vaadin for UI, Spring for middleware infrastructure and EclipseLink ORM. Also, you will be able to see how it’s made from inside, cause CUBA has open source code.