2016-01-28 272 views
0

我使用xml來配置休眠和使用PostreSQL DBMS,但我得到一個錯誤。這在使用hibernate.properties文件和編程使用配置時起作用,但使用xml似乎有點棘手。休眠xml配置

她是hibernate.cfg.xml文件女巫發生在資源文件:

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

<hibernate-configuration> 

    <session-factory> 

     <!-- Database connection settings --> 
     <property name="connection.driver_class">org.postgresql.Driver</property> 
     <property name="connection.url">jdbc:postgresql://localhost:5432/miniIventory</property> 
     <property name="connection.username">postgres</property> 
     <property name="connection.password">adsginie2roboform</property> 


     <!-- SQL dialect --> 
     <property name="dialect">org.hibernate.dialect.PostgreSQL82Dialect</property> 

     <!-- Echo all executed SQL to stdout --> 
     <property name="show_sql">true</property> 

     <mapping class="model.Product"/> 
     <mapping class="model.Purchase"/> 

    </session-factory> 

</hibernate-configuration> 

下面是DatabaseUtil類:

public class DatabaseUtil { 
    private static final SessionFactory sessionFactory = buildSessionFactory(); 

    private static SessionFactory buildSessionFactory() { 
     try { 
      return new Configuration().configure().buildSessionFactory(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
      throw new RuntimeException("There was an error building the factor"); 
     } 
    } 

    public static SessionFactory getSessionFactory() { 
     return sessionFactory; 
    } 

} 

這裏是堆棧跟蹤:

org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister 
    at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:123) 
    at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:77) 
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:346) 
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) 
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708) 
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724) 
    at util.DatabaseUtil.buildSessionFactory(DatabaseUtil.java:14) 
    at util.DatabaseUtil.<clinit>(DatabaseUtil.java:10) 
    at dao.DAO.<init>(DAO.java:13) 
    at dao.ProductDAO.<init>(ProductDAO.java:14) 
    at controller.product.searchProductController.parentTableProperties(searchProductController.java:79) 
    at controller.product.searchProductController.tableViewProperties(searchProductController.java:73) 
    at controller.product.searchProductController.initialize(searchProductController.java:63) 
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552) 
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2445) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2413) 
    at controller.purchase.PurchaseController.btnAddProductClicked(PurchaseController.java:138) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:497) 
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71) 
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:497) 
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275) 
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1767) 
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1653) 
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) 
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) 
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49) 
    at javafx.event.Event.fireEvent(Event.java:198) 
    at javafx.scene.Node.fireEvent(Node.java:8390) 
    at javafx.scene.control.Button.fire(Button.java:185) 
    at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182) 
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96) 
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89) 
    at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218) 
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) 
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) 
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54) 
    at javafx.event.Event.fireEvent(Event.java:198) 
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3758) 
    at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3486) 
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762) 
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2495) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:350) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$350(GlassViewEventHandler.java:385) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$278/1881378835.get(Unknown Source) 
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:404) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:384) 
    at com.sun.glass.ui.View.handleMouseEvent(View.java:555) 
    at com.sun.glass.ui.View.notifyMouse(View.java:927) 
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
    at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101) 
    at com.sun.glass.ui.win.WinApplication$$Lambda$38/658471308.run(Unknown Source) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: org.hibernate.PropertyAccessException: Exception occurred inside getter of model.Purchase.idPurchase 
    at org.hibernate.property.access.spi.GetterMethodImpl.get(GetterMethodImpl.java:44) 
    at org.hibernate.engine.internal.UnsavedValueFactory.getUnsavedIdentifierValue(UnsavedValueFactory.java:68) 
    at org.hibernate.tuple.PropertyFactory.buildIdentifierAttribute(PropertyFactory.java:61) 
    at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:141) 
    at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:509) 
    at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:124) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422) 
    at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:96) 
    ... 76 more 
Caused by: java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:497) 
    at org.hibernate.property.access.spi.GetterMethodImpl.get(GetterMethodImpl.java:41) 
    ... 86 more 
Caused by: java.lang.NullPointerException 
    at model.Purchase.getIdPurchase(Purchase.java:30) 
    ... 91 more 
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException 
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1770) 
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1653) 
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) 
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) 
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49) 
    at javafx.event.Event.fireEvent(Event.java:198) 
    at javafx.scene.Node.fireEvent(Node.java:8390) 
    at javafx.scene.control.Button.fire(Button.java:185) 
    at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182) 
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96) 
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89) 
    at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218) 
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) 
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) 
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54) 
    at javafx.event.Event.fireEvent(Event.java:198) 
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3758) 
    at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3486) 
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762) 
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2495) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:350) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$350(GlassViewEventHandler.java:385) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$278/1881378835.get(Unknown Source) 
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:404) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:384) 
    at com.sun.glass.ui.View.handleMouseEvent(View.java:555) 
    at com.sun.glass.ui.View.notifyMouse(View.java:927) 
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
    at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101) 
    at com.sun.glass.ui.win.WinApplication$$Lambda$38/658471308.run(Unknown Source) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:497) 
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71) 
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:497) 
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275) 
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1767) 
    ... 50 more 
Caused by: java.lang.ExceptionInInitializerError 
    at dao.DAO.<init>(DAO.java:13) 
    at dao.ProductDAO.<init>(ProductDAO.java:14) 
    at controller.product.searchProductController.parentTableProperties(searchProductController.java:79) 
    at controller.product.searchProductController.tableViewProperties(searchProductController.java:73) 
    at controller.product.searchProductController.initialize(searchProductController.java:63) 
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552) 
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2445) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2413) 
    at controller.purchase.PurchaseController.btnAddProductClicked(PurchaseController.java:138) 
    ... 60 more 
Caused by: java.lang.RuntimeException: There was an error building the factor 
    at util.DatabaseUtil.buildSessionFactory(DatabaseUtil.java:17) 
    at util.DatabaseUtil.<clinit>(DatabaseUtil.java:10) 
    ... 69 more 
DEBUG - Connection pool now considered primed; min-size will be maintained 
+1

堆棧跟蹤說:造成:org.hibernate.PropertyAccessException:發生內部model.Purchase.idPurchase –

+1

的吸氣例外,它說什麼異常是和它發生的地方:'java.lang.NullPointerException at model.Purchase.getIdPurchase(Purchase.java:30)' –

+0

好吧錯誤是由非初始化屬性造成的 –

回答

0

問題是由未初始化的屬性造成的。爲了解決這個問題我有intialize所有屬性在採購類,像這樣:

public class Purchase { 
    private LongProperty idPurchase; 
    private StringProperty codePurchase; 
    private ObjectProperty<LocalDate> datePurchase; 
    private DoubleProperty totalHt; 
    private DoubleProperty tva; 
    private DoubleProperty totalTTC; 

    public Purchase() { 
     this.idPurchase = new SimpleLongProperty(); 
     this.codePurchase = new SimpleStringProperty(); 
     this.datePurchase = new SimpleObjectProperty<>(); 
     this.totalHt = new SimpleDoubleProperty(); 
     this.tva = new SimpleDoubleProperty(); 
     this.totalTTC = new SimpleDoubleProperty(); 
    } 

} 
+1

哦,我的! long,String,double和LocalDate有什麼問題?你爲什麼要把所有東西都包裝到這些Property類中? –

+0

是的,我有,那是什麼? –

+0

@abdouamer你如何繪製這些東西? –