0

Need a good example from Hibernate + zk

asked 2010-10-28 14:58:21 +0800

jdecuirm gravatar image jdecuirm
75

Good afternoon Zk friends, i'm using zk + hibernate but i need a good example about how could i insert data from .zul pages to a database using MySQL, to see how hibernate works! if you can give me a source with java + zk + hibernate that would be awesome! Thanks for reading!!

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2010-10-28 19:54:56 +0800

samchuang gravatar image samchuang
4084 4

Hi

you an search "Hibernate" in ZK

here is one I found

link publish delete flag offensive edit

answered 2010-10-28 21:50:08 +0800

jdecuirm gravatar image jdecuirm
75

Hi, thanks for the reply! i tried that tutorial without success! but i'll post my code so you can check it! and if you can help i will thank you a lot!

Login.Java

package siid;
import org.zkoss.zk.ui.util.GenericAutowireComposer;
import org.zkoss.zul.*;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class Login extends GenericAutowireComposer {
/**
*
*/
private static final long serialVersionUID = 1L;
private Textbox txUsuario;
private Textbox txContrasena;
private Textbox txTipo;
private Textbox txCampus;
private Button btAdd;

private void onBtnClick(){
Session session = null;
try{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");
Login login = new Login();
login.setTxUsuario(txUsuario);
login.setTxContrasena(txContrasena);
login.setTxTipo(txTipo);
login.setTxCampus(txCampus);
session.save(login);
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
session.flush();
session.close();

}

}

private void setTxUsuario(Textbox txUsuario) {
this.txUsuario = txUsuario;
}

private Textbox getTxUsuario() {
return txUsuario;
}

private void setTxContrasena(Textbox txContrasena) {
this.txContrasena = txContrasena;
}

private Textbox getTxContrasena() {
return txContrasena;
}

private void setTxTipo(Textbox txTipo) {
this.txTipo = txTipo;
}

private Textbox getTxTipo() {
return txTipo;
}

private void setTxCampus(Textbox txCampus) {
this.txCampus = txCampus;
}

private Textbox getTxCampus() {
return txCampus;
}


}

index.zul

<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<zscript><![CDATA[//@IMPORT
import siid.*;
]]></zscript>
<window apply="Login" title="new page title" border="normal">
<vbox>
<textbox id="txUsuario"></textbox>
<textbox id="txContrasena"></textbox>
<textbox id="txTipo"></textbox>
<textbox id="txCampus"></textbox>
<button id="btAdd" label = "Agregar" forward="onClick=onBtnClick"></button>
</vbox>
</window>
</zk>

hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/siid</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">111</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="Login.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Login.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="siid.Login" table="tblogin">
<id name="idLogin" type="int" column="Usuario" >
<generator class="assigned"/>
</id>

<property name="Contrasena">
<column name="Contrasena" />
</property>
<property name="Tipo">
<column name="Tipo"/>
</property>
<property name="Campus">
<column name="Campus"/>
</property>
</class>
</hibernate-mapping>

That's my code, but i don't know what it does not respond i get the http 404 error what should i do?

link publish delete flag offensive edit

answered 2010-10-29 06:13:33 +0800

samchuang gravatar image samchuang
4084 4

404 ? maybe you can check tomcat setting ?see if visit the correct url ?

link publish delete flag offensive edit

answered 2010-10-31 18:03:53 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2010-10-31 18:04:35 +0800

It's possible to have to answer two questions in the 'new user registration' about the zk framework for verifying a really new user.
That's very angry with these spamers.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-10-28 14:58:21 +0800

Seen: 994 times

Last updated: Oct 31 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More