org.hibernate.MappingException:无法获取org.hibernate.persister.entity.SingleTableEntityPersister的构造函数

时间:2016-06-01 17:06:03

标签: java hibernate nhibernate-mapping

我实际上是hibernate的新手,并试图建立一个类,供应商。 以下是一些细节。

的hibernate.cfg.xml

<head>
  <title>App</title>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %> # problematic line
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
</head>

hibernate.reveng.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.MySQLDialect</property>
      <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/transaksi?zeroDateTimeBehavior=convertToNull</property>
      <property name="hibernate.connection.username">root</property>
      <property name="hibernate.show_sql">true</property>
      <property name="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory</property>
      <property name="hibernate.format_sql">true</property>
      <mapping resource="Pojo/Supplier.hbm.xml"/>
   </session-factory>
</hibernate-configuration>

Supplier.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
   <schema-selection match-catalog="transaksi"/>
   <table-filter match-name="supplier"/>
</hibernate-reverse-engineering>

Supplier.java

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 1, 2016 9:01:44 PM by Hibernate Tools 4.3.1 -->
<hibernate-mapping>
<class name="Pojo.Supplier" table="supplier" catalog="transaksi"    optimistic-lock="version">
    <id name="kdSup" type="string">
        <column name="kd_sup" length="25" />
        <generator class="assigned" />
    </id>
    <property name="nmSup" type="string">
        <column name="nm_sup" length="25" not-null="true" />
    </property>
    <property name="nmBrg" type="string">
        <column name="nm_brg" length="25" not-null="true" />
    </property>
    <property name="hrg" type="int">
        <column name="hrg" not-null="true" />
    </property>
    <property name="jml" type="int">
        <column name="jml" not-null="true" />
    </property>
    <property name="tgl" type="date">
        <column name="tgl" length="10" not-null="true" />
    </property>
    <property name="FStatus" type="int">
        <column name="f_status" not-null="true" />
    </property>
    <property name="FUpdate" type="int">
        <column name="f_update" not-null="true" />
    </property>
</class>
</hibernate-mapping>

SupplierGui.java

package Pojo;

import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name ="supplier")
public class Supplier  implements java.io.Serializable {


 @Id
 private String kdSup;
 private String nmSup;
 private String nmBrg;
 private String hrg;
 private String jml;
 private Date tgl;
 private String FStatus;
 private String FUpdate;

public Supplier() {
}

public Supplier(String kdSup, String nmSup, String nmBrg, String hrg, String jml, Date tgl, String FStatus, String FUpdate) {
   this.kdSup = kdSup;
   this.nmSup = nmSup;
   this.nmBrg = nmBrg;
   this.hrg = hrg;
   this.jml = jml;
   this.tgl = tgl;
   this.FStatus = FStatus;
   this.FUpdate = FUpdate;
}

public String getKdSup() {
    return this.kdSup;
}

public void setKdSup(String kdSup) {
    this.kdSup = kdSup;
}
public String getNmSup() {
    return this.nmSup;
}

public void setNmSup(String nmSup) {
    this.nmSup = nmSup;
}
public String getNmBrg() {
    return this.nmBrg;
}

public void setNmBrg(String nmBrg) {
    this.nmBrg = nmBrg;
}
public String getHrg() {
    return this.hrg;
}

public void setHrg(String hrg) {
    this.hrg = hrg;
}
public String getJml() {
    return this.jml;
}

public void setJml(String jml) {
    this.jml = jml;
}
public Date getTgl() {
    return this.tgl;
}

public void setTgl(Date tgl) {
    this.tgl = tgl;
}
public String getFStatus() {
    return this.FStatus;
}

public void setFStatus(String FStatus) {
    this.FStatus = FStatus;
}
public String getFUpdate() {
    return this.FUpdate;
}

public void setFUpdate(String FUpdate) {
    this.FUpdate = FUpdate;
}

}

SupplierDAO.java

package Gui;
import Pojo.Supplier;
import java.util.List;

public interface SupplierGui {

    List<Supplier> listSupplier(); 
}

这是主要班级......

frmSupplier.java

package DAO;
import Pojo.Supplier;
import Gui.SupplierGui;
import Util.HibernateUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import javax.persistence.EntityManager;
import javax.swing.JOptionPane;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.Criteria;
import org.hibernate.Query;

public class SupplierDAO implements SupplierGui {

private SessionFactory sessionFactory;

public SupplierDAO(SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory;
}

@Override
public List<Supplier> listSupplier() {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    List list = new ArrayList();
    try {
        Query query = session.createQuery("from supplier where f_status = '1'");
        list = query.list();
        session.getTransaction().commit();
    } catch (IllegalStateException ex) {
        session.getTransaction().rollback();
        JOptionPane.showMessageDialog(null, ex);
    }
    return list;
 }

 } 

HibernateUtil.java

package Tampilan;
import java.sql.*;
import java.text.ParseException;
import javax.swing.*;
import java.lang.*;
import java.awt.*;
import javax.swing.table.DefaultTableModel;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Date;

import Pojo.Supplier;
import Gui.SupplierGui;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import Util.HibernateUtil;
import Util.SupplierTableModel;
import java.util.Calendar;

public class frmSupplier extends javax.swing.JFrame {

private SupplierGui supplierInters = HibernateUtil.getSupplier();
private Supplier sup;
private List listSuplierAll = new ArrayList();

String tanggal;

public frmSupplier() {
    initComponents();
    BacaTabelSupplier();    }

private void BacaTabelSupplier(){        
    try{
        listSuplierAll = supplierInters.listSupplier();

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, ex);
    }
    String[][] data1 = new String[listSuplierAll.size()][6];
    for (int x = 0; x < listSuplierAll.size(); x++) {
        Supplier tm1 = (Supplier) listSuplierAll.get(x);
        data1[x][0] = tm1.getKdSup();
        data1[x][1] = tm1.getNmSup();
        data1[x][2] = tm1.getNmBrg();
        data1[x][3] = tm1.getHrg();
        data1[x][4] = tm1.getJml();
        data1[x][5] = tm1.getTgl().toString();
    }
    String[] label = {"Kode Supplier","Nama Supplier","Nama Barang","Harga Satuan",
                        "Jumlah","Tanggal"};
    DefaultTableModel model = new DefaultTableModel(data1, label);
    tabel.setModel(model);

}

public static void main(String args[]) {

    java.awt.EventQueue.invokeLater(new Runnable() {

        public void run() {
            new frmSupplier().setVisible(true);
        }
    });
}

}

这是我的问题。

org.hibernate.MappingException:无法获取org.hibernate.persister.entity.SingleTableEntityPersister的构造函数

package Util;

import DAO.SupplierDAO;
import Gui.SupplierGui;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;

public class HibernateUtil {

private static final SessionFactory sessionFactory;
private static final SupplierGui supplierInter;

static {
        try{
        sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
        supplierInter = new SupplierDAO(sessionFactory);
        } catch (Throwable ex) {
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}

public static SessionFactory getSessionFactory() {
    return sessionFactory;
}

public static SupplierGui getSupplier() {
    return supplierInter;
}

}

this is my structure package

我真的不知道他们代码中的错误在哪里,有人可以帮助我吗?我是新来的尝试休眠,如果你想帮助我,我真的很开心。

thanks =)

1 个答案:

答案 0 :(得分:0)

我认为您可以通过将此行添加到hibernate.cfg.xml

来解决

<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>