org.hibernate.HibernateException:无法实例化默认的tuplizer

时间:2015-12-02 00:07:23

标签: java hibernate

配置我的第一个hibernate程序时遇到问题,但是我在这个过程的最后一步陷入困境。 这是堆栈跟踪:

JCheckBoxMenuItem

我的映射文件(Student.hbm.xml):

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class Test {

    public static void main(String[] args) {
        new Test();
    }

    public Test() {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    ex.printStackTrace();
                }

                JMenuBar mb = new JMenuBar();
                JMenu menu = new JMenu("Lots-o-stuff");
                mb.add(menu);

                menu.add(new MyMenuItem("Apples"));
                menu.add(new MyMenuItem("Pears"));
                menu.add(new MyMenuItem("Bananas"));

                JFrame frame = new JFrame("Testing");
                frame.setJMenuBar(mb);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.add(new TestPane());
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        });
    }

    public class TestPane extends JPanel {

        public TestPane() {
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(200, 200);
        }

    }

    public class MyMenuItem extends JCheckBoxMenuItem {

        public MyMenuItem() {
        }

        public MyMenuItem(Icon icon) {
            super(icon);
        }

        public MyMenuItem(String text) {
            super(text);
        }

        public MyMenuItem(Action a) {
            super(a);
        }

        public MyMenuItem(String text, Icon icon) {
            super(text, icon);
        }

        public MyMenuItem(String text, boolean b) {
            super(text, b);
        }

        public MyMenuItem(String text, Icon icon, boolean b) {
            super(text, icon, b);
        }

        @Override
        protected void processMouseEvent(MouseEvent evt) {
            if (evt.getID() == MouseEvent.MOUSE_RELEASED && contains(evt.getPoint())) {
                doClick();
                setArmed(true);
            } else {
                super.processMouseEvent(evt);
            }
        }
    }

}

我的hibernate配置文件(hibernate.cfg.xml):

Dec 01, 2015 6:54:34 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.5.6-Final
Dec 01, 2015 6:54:34 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Dec 01, 2015 6:54:34 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : javassist
Dec 01, 2015 6:54:34 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Dec 01, 2015 6:54:34 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: hibernate.cfg.xml
Dec 01, 2015 6:54:34 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: hibernate.cfg.xml
Dec 01, 2015 6:54:34 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : edu/aspire/li/Student.hbm.xml
Dec 01, 2015 6:54:34 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: edu.aspire.li.Student -> STUDENT
Dec 01, 2015 6:54:34 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Dec 01, 2015 6:54:34 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Dec 01, 2015 6:54:34 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Dec 01, 2015 6:54:34 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Dec 01, 2015 6:54:34 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: oracle.jdbc.OracleDriver at URL: jdbc:oracle:thin:@localhost:1521:XE
Dec 01, 2015 6:54:34 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=system, password=****, autocommit=false}
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Oracle, version: Oracle Database 11g Release 11.1.0.0.0 - Production
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Oracle JDBC driver, version: 10.2.0.1.0XE
Dec 01, 2015 6:54:35 PM org.hibernate.dialect.resolver.StandardDialectResolver resolveDialectInternal
WARNING: Oracle 11g is not yet fully supported; using 10g dialect
Dec 01, 2015 6:54:35 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.Oracle10gDialect
Dec 01, 2015 6:54:35 PM org.hibernate.engine.jdbc.JdbcSupportLoader useContextualLobCreation
INFO: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
Dec 01, 2015 6:54:35 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
Dec 01, 2015 6:54:35 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: enabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Dec 01, 2015 6:54:35 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory createRegionFactory
INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Check Nullability in Core (should be disabled when Bean Validation is on): enabled
Dec 01, 2015 6:54:35 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Exception in thread "main" org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
    at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:110)
    at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:135)
    at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:80)
    at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:323)
    at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:475)
    at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:133)
    at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:297)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385)
    at edu.aspire.daos.InsertStudent.main(InsertStudent.java:15)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:107)
    ... 9 more
Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for sname in class edu.aspire.li.Student
    at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:328)
    at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:321)
    at org.hibernate.mapping.Property.getGetter(Property.java:304)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:299)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:158)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:77)
    ... 14 more

和我的InsertStudent类:

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
 <hibernate-mapping> 
    <class name="edu.aspire.li.Student" table="STUDENT"> 
        <!-- id property --> 
        <id name="sno" column="SNO" type="integer" >
            <!--   Primary key generator class --> 
                <generator class="assigned"/>
        </id>
        <!-- common properties -->
        <property name ="sname" column="SNAME" type="string" length="100"/>
        <property name ="email" column="EMAIL" type="string" length="100"/>
        <property name ="mobile" column="MOBILE" type="long" not-null="true"/>
    </class>
  </hibernate-mapping>

我将我的学生班,student.hbm.xml放在edu.aspire.li中,我的插入学生班在edu.aspire.daos中,我的hibernate.cfg.xml放在默认包中。

提前致谢。

3 个答案:

答案 0 :(得分:2)

使用JDK11运行Spring Boot 2.0.5时出现此错误。要修复它,我必须更新javassist库版本(Gradle是我的构建工具):

compile('org.javassist:javassist:3.23.1-GA') {force = true}

有关迁移到JDK11的更多信息,我发现this博客文章很有用。或者,upgrading to Spring Boot to 2.1 will fix this issue

答案 1 :(得分:1)

您是否在JDK 11上运行Spring Boot? 当我切换到JDK 11时遇到了同样的问题。 我通过更改Spring Boot版本来解决它。

答案 2 :(得分:0)

感谢@ cpierceworld,我宣布我的学生为

package edu.aspire.li;

import java.io.Serializable;

public class Student implements Serializable{
    private int sno;
    private String name;
    private String email;
    private long mobile;    

    public Student(){
        System.out.println("This is to construct student");
    }
    public int getSno() {
        return sno;
    }
    public void setSno(int sno) {
        this.sno = sno;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public long getMobile() {
        return mobile;
    }
    public void setMobile(long mobile) {
        this.mobile = mobile;
    }


}

与student.hbm.xml存在名称冲突

<property name ="sname" column="SNAME" type="string" length="100"/>