Hibernate Session is not open Using Javafx -
i developing simple application in javafx hibernate using netbeans 7.3.1
in small project have connected hibernate using wizards setup. want show company table data in tableview using hibernate. when run app showing error message below:
info: building session factory initial sessionfactory creation failed.net.sf.cglib.core.codegenerationexception: java.lang.reflect.invocationtargetexception-->null java.lang.runtimeexception: java.lang.reflect.invocationtargetexception @ javafx.fxml.fxmlloader$controllermethodeventhandler.handle(fxmlloader.java:1440) @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent (compositeeventhandler.java:69) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent (eventhandlermanager.java:217) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent (eventhandlermanager.java:170) @ com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent (compositeeventdispatcher.java:38)
have following files:
1. hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-configuration public "-//hibernate/hibernate configuration dtd 3.0//en" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.derbydialect</property> <property name="hibernate.connection.driver_class"> org.apache.derby.jdbc.clientdriver</property> <property name="hibernate.connection.url"> jdbc:derby://localhost:1527/sample</property> <property name="hibernate.connection.username">app</property> <property name="hibernate.connection.password">app</property> <property name="hibernate.show_sql">true</property> <property name="hibernate.query.factory_class"> org.hibernate.hql.ast.astquerytranslatorfactory</property> <mapping resource="sample/entity/company.hbm.xml"/> </session-factory> </hibernate-configuration>
2. hibernate.reveng.xml
3. hibernateutil.java
package sample.util; import org.hibernate.cfg.annotationconfiguration; import org.hibernate.sessionfactory; public class hibernateutil { private static final sessionfactory sessionfactory; static { try { // create sessionfactory standard (hibernate.cfg.xml) // config file. sessionfactory = new annotationconfiguration().configure().buildsessionfactory(); } catch (throwable ex) { // log exception. system.err.println("initial sessionfactory creation failed." + ex); throw new exceptionininitializererror(ex); } } public static sessionfactory getsessionfactory() { return sessionfactory; } } **4. company.java** package sample.entity; // generated aug 6, 2013 12:55:08 pm hibernate tools 3.2.1.ga import java.util.date; /** * company generated hbm2java */ public class company implements java.io.serializable { private integer id; private string companyname; private string companylogo; private string ownername; private string address1; private string address2; private string city; private string state; private string pincode; private string countrycode; private string country; private string areacode; private string offphoneno; private string offfaxno; private string emailid; private string tanno; private string panno; private string website; private date updt; private date uptm; public company() { } public company(string companyname, string companylogo, string ownername, string address1, string address2, string city, string state, string pincode, string countrycode, string country, string areacode, string offphoneno, string offfaxno, string emailid, string tanno, string panno, string website, date updt, date uptm) { this.companyname = companyname; this.companylogo = companylogo; this.ownername = ownername; this.address1 = address1; this.address2 = address2; this.city = city; this.state = state; this.pincode = pincode; this.countrycode = countrycode; this.country = country; this.areacode = areacode; this.offphoneno = offphoneno; this.offfaxno = offfaxno; this.emailid = emailid; this.tanno = tanno; this.panno = panno; this.website = website; this.updt = updt; this.uptm = uptm; } public integer getid() { return this.id; } public void setid(integer id) { this.id = id; } public string getcompanyname() { return this.companyname; } public void setcompanyname(string companyname) { this.companyname = companyname; } public string getcompanylogo() { return this.companylogo; } public void setcompanylogo(string companylogo) { this.companylogo = companylogo; } public string getownername() { return this.ownername; } public void setownername(string ownername) { this.ownername = ownername; } public string getaddress1() { return this.address1; } public void setaddress1(string address1) { this.address1 = address1; } public string getaddress2() { return this.address2; } public void setaddress2(string address2) { this.address2 = address2; } public string getcity() { return this.city; } public void setcity(string city) { this.city = city; } public string getstate() { return this.state; } public void setstate(string state) { this.state = state; } public string getpincode() { return this.pincode; } public void setpincode(string pincode) { this.pincode = pincode; } public string getcountrycode() { return this.countrycode; } public void setcountrycode(string countrycode) { this.countrycode = countrycode; } public string getcountry() { return this.country; } public void setcountry(string country) { this.country = country; } public string getareacode() { return this.areacode; } public void setareacode(string areacode) { this.areacode = areacode; } public string getoffphoneno() { return this.offphoneno; } public void setoffphoneno(string offphoneno) { this.offphoneno = offphoneno; } public string getofffaxno() { return this.offfaxno; } public void setofffaxno(string offfaxno) { this.offfaxno = offfaxno; } public string getemailid() { return this.emailid; } public void setemailid(string emailid) { this.emailid = emailid; } public string gettanno() { return this.tanno; } public void settanno(string tanno) { this.tanno = tanno; } public string getpanno() { return this.panno; } public void setpanno(string panno) { this.panno = panno; } public string getwebsite() { return this.website; } public void setwebsite(string website) { this.website = website; } public date getupdt() { return this.updt; } public void setupdt(date updt) { this.updt = updt; } public date getuptm() { return this.uptm; } public void setuptm(date uptm) { this.uptm = uptm; } }
5. company.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"> <!-- generated aug 6, 2013 12:55:08 pm hibernate tools 3.2.1.ga --> <hibernate-mapping> <class name="sample.entity.company" table="company" catalog="sample"> <id name="id" type="java.lang.integer"> <column name="id" /> <generator class="identity" /> </id> <property name="companyname" type="string"> <column name="companyname" length="100" /> </property> <property name="companylogo" type="string"> <column name="companylogo" length="50" /> </property> <property name="ownername" type="string"> <column name="ownername" length="50" /> </property> <property name="address1" type="string"> <column name="address1" length="50" /> </property> <property name="address2" type="string"> <column name="address2" length="50" /> </property> <property name="city" type="string"> <column name="city" length="30" /> </property> <property name="state" type="string"> <column name="state" length="30" /> </property> <property name="pincode" type="string"> <column name="pincode" length="10" /> </property> <property name="countrycode" type="string"> <column name="countrycode" length="10" /> </property> <property name="country" type="string"> <column name="country" length="30" /> </property> <property name="areacode" type="string"> <column name="areacode" length="30" /> </property> <property name="offphoneno" type="string"> <column name="offphoneno" length="15" /> </property> <property name="offfaxno" type="string"> <column name="offfaxno" length="15" /> </property> <property name="emailid" type="string"> <column name="emailid" length="50" /> </property> <property name="tanno" type="string"> <column name="tanno" length="35" /> </property> <property name="panno" type="string"> <column name="panno" length="35" /> </property> <property name="website" type="string"> <column name="website" length="30" /> </property> <property name="updt" type="date"> <column name="updt" length="10" /> </property> <property name="uptm" type="time"> <column name="uptm" length="8" /> </property> </class> </hibernate-mapping>
using code below, want fetch data:
@fxml void initialize() { assert btnquery != null : "fx:id=\"btnquery\" not injected: check fxml file 'testing.fxml'."; assert tableview != null : "fx:id=\"tableview\" not injected: check fxml file 'testing.fxml'."; assert txtname != null : "fx:id=\"txtname\" not injected: check fxml file 'testing.fxml'."; } private string query_all = "from company"; @fxml void btnqueryclick(actionevent event) { executehqlquery(query_all); } private void executehqlquery(string hql) { try { session session = hibernateutil.getsessionfactory().opensession(); session.begintransaction(); query q = session.createquery(hql); system.out.println(hql); list resultlist = q.list(); displayresult(resultlist); session.gettransaction().commit(); } catch (hibernateexception he) { he.printstacktrace(); } }
this exception generated:
session session = hibernateutil.getsessionfactory().opensession();
log output:
info: building session factory initial sessionfactory creation failed.net.sf.cglib.core.codegenerationexception: java.lang.reflect.invocationtargetexception-->null java.lang.runtimeexception: java.lang.reflect.invocationtargetexception @ javafx.fxml.fxmlloader$controllermethodeventhandler.handle (fxmlloader.java:1440)"
i have tried same in simple swing application there hibernate connectivity working fine, using javafx showing troubles listed above.
hibernate in javafx compatible netbeans 7.4 version. netbeans version 7.3 or below not suitable javafx.
instead of making use of reverse engineering wizard. can work pojo's , mapping files.
Comments
Post a Comment