0

Netbeans 7.3.1を使用して、Hibernateを使用してJavafxで単純なアプリケーションを開発しています

小さなプロジェクトでは、ウィザードのセットアップを使用して休止状態に接続しました。休止状態を使用して、TableView で会社のテーブル データを表示したいと考えています。しかし、このアプリを実行すると、以下のエラー メッセージが表示されます。

    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
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1440)
at 
    com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent
    (CompositeEventHandler.java:69)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent
    (EventHandlerManager.java:217)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent
    (EventHandlerManager.java:170)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent
    (CompositeEventDispatcher.java:38)


次のファイルがあります。

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 the SessionFactory from standard (hibernate.cfg.xml) 
        // config file.
        sessionFactory = 
          new AnnotationConfiguration().configure().buildSessionFactory();
    } catch (Throwable ex) {
        // Log the 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 by Hibernate Tools 3.2.1.GA


import java.util.Date;

/**
 * Company generated by 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 by 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>

以下のコードを使用して、データをフェッチします。

@FXML   
void initialize() {
    assert btnQuery != null : "fx:id=\"btnQuery\" was not injected: check your 
      FXML  file 'testing.fxml'.";
    assert tableview != null : "fx:id=\"tableview\" was not injected: check your 
      FXML file 'testing.fxml'.";
    assert txtName != null : "fx:id=\"txtName\" was not injected: check your 
      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();
    }
}

これは生成された例外です:

  Session session = HibernateUtil.getSessionFactory().openSession();

ログ出力:

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
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle
      (FXMLLoader.java:1440)"

Hibernate接続が正常に機能しているSimple Swingアプリケーションで同じことを試しましたが、javafxを使用すると上記の問題が表示されます。

4

2 に答える 2

0

JavaFx の Hibernate は、NetBeans 7.4 バージョンと互換性があります。NetBeans バージョン 7.3 以下は、JavaFx には適していません。

リバース エンジニアリング ウィザードを使用する代わりに。POJO とマッピング ファイルを簡単に操作できます。

于 2013-10-31T05:28:41.250 に答える
0

HibernateUtil クラスを使用せずにこれを行いました

次のコードでセッションを取得できます。これは私のコントローラー部分です。そして、それは私にとってはうまくいきます

Session session = null;
        Transaction tx = null;
        SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
List<Sample> results = null;

        try {

            session = sessionFactory.openSession();
            tx = session.beginTransaction();
            Criteria cr = session.createCriteria(Sample.class);
            //cr.add(Restrictions.eq("qualification", "yes"));
            results = cr.list();
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
            tx.rollback();
        }
于 2013-10-09T10:37:21.823 に答える