Hibernate buildSessionFactory中的ArrayIndexOutOfBoundsException

时间:2015-11-03 10:00:04

标签: java mysql hibernate sessionfactory

当我尝试在hibernate中打开一个新会话时,我得到了ArrayIndexOutOfBoundsException。  我正在使用带有MySQL方言的Hibernate 3.8。

请帮我解决此错误。

这是代码

HibernateTest.java

    import java.text.ParseException;
    import java.text.SimpleDateFormat;

    import org.hibernate.Session;
    import org.hibernate.Transaction;
    import org.hibernate.cfg.Configuration;

    import com.bean.Address;
    import com.bean.UserDetails;

    public class HibernateTest {

        public static void main(String[] args) throws ParseException {

            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

            Session session = HibernateUtil.getSessionFactory().openSession();
            Transaction t = session.beginTransaction();
            UserDetails user1 = new UserDetails();
            user1.setUsername("chetanj257");
            user1.setDob(sdf.parse("25/06/1992"));
            Address homeAddress = new Address();
            homeAddress.setStreet("KR Nagar");
            homeAddress.setCity("Harihar");
            homeAddress.setState("Karnataka");
            homeAddress.setPincode(577601);
            Address officeAddress = new Address();
            officeAddress.setStreet("ITPL");
            officeAddress.setCity("Bangalore");
            officeAddress.setState("Karnataka");
            officeAddress.setPincode(560045);
            user1.getAddresses().add(homeAddress);
            user1.getAddresses().add(officeAddress);
            session.save(user1);
            t.commit();
        }
    }

我用它来获取SessionFactory对象

HibernateUtil.java

import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;

    public class HibernateUtil {
        private static SessionFactory sessionFactory = null;

        static  {
            sessionFactory =  new Configuration().configure().buildSessionFactory();
        }
        public static SessionFactory getSessionFactory() {
            return sessionFactory;
        }
    }

hibernate.cfg.xml中

  <!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="connection.driver_class">com.mysql.jdbc.Driver</property> 
         <property name="connection.url">jdbc:mysql://localhost:3306/test</property> 
         <property name="connection.username">root</property> 
         <property name="connection.password">root</property> 

         <property name="connection.pool_size">1</property> 

         <property name="dialect">org.hibernate.dialect.MySQLDialect</property> 

         <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> 

         <property name="show_sql">true</property> 

         <property name="hbm2ddl.auto">update</property> 

      <mapping class="com.bean.UserDetails"/>

     </session-factory> 
 </hibernate-configuration>

错误StackTrace:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at main.HibernateTest.main(HibernateTest.java:19)
Caused by: java.lang.ArrayIndexOutOfBoundsException: -66
    at org.hibernate.persister.entity.AbstractEntityPersister.checkVersion(AbstractEntityPersister.java:2046)
    at org.hibernate.persister.entity.AbstractEntityPersister.generateUpdateString(AbstractEntityPersister.java:2001)
    at org.hibernate.persister.entity.AbstractEntityPersister.generateUpdateString(AbstractEntityPersister.java:1967)
    at org.hibernate.persister.entity.AbstractEntityPersister.postConstruct(AbstractEntityPersister.java:3148)
    at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:439)
    at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:286)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872)
    at main.HibernateUtil.<clinit>(HibernateUtil.java:10)
    ... 1 more

0 个答案:

没有答案