Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate buildSessionFactory() Exception
    primarykey
    data
    text
    <p>I have a serious problem with hibernate. I followed various books und online tutorials, but I ever get the same Exception "ExceptionInInitializerError" obviously thrown by the HibernateUtil.java Line</p> <pre><code>SessionFactory sf = cfg.configure().buildSessionFactory(); </code></pre> <p>My Tomcat log says the following:</p> <pre><code>Caused by: java.lang.ExceptionInInitializerError at de.marcelstuht.nerven2.server.HibernateUtil.buildSessionFactory(HibernateUtil.java:23) at de.marcelstuht.nerven2.server.HibernateUtil.&lt;clinit&gt;(HibernateUtil.java:8) at de.marcelstuht.nerven2.shared.model.Account.&lt;init&gt;(Account.java:52) at de.marcelstuht.nerven2.server.GreetingServiceImpl.loginServer(GreetingServiceImpl.java:39) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569) ... 21 more Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:180) at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:131) at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:345) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775) at de.marcelstuht.nerven2.server.HibernateUtil.buildSessionFactory(HibernateUtil.java:18) ... 29 more Caused by: org.hibernate.InstantiationException: could not instantiate test objectde.marcelstuht.nerven2.shared.model.Account at org.hibernate.engine.internal.UnsavedValueFactory.instantiate(UnsavedValueFactory.java:49) at org.hibernate.engine.internal.UnsavedValueFactory.getUnsavedIdentifierValue(UnsavedValueFactory.java:68) at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:75) at org.hibernate.tuple.entity.EntityMetamodel.&lt;init&gt;(EntityMetamodel.java:143) at org.hibernate.persister.entity.AbstractEntityPersister.&lt;init&gt;(AbstractEntityPersister.java:498) at org.hibernate.persister.entity.SingleTableEntityPersister.&lt;init&gt;(SingleTableEntityPersister.java:142) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:158) ... 34 more Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.hibernate.engine.internal.UnsavedValueFactory.instantiate(UnsavedValueFactory.java:46) ... 44 more Caused by: java.lang.NullPointerException at de.marcelstuht.nerven2.shared.model.Account.&lt;init&gt;(Account.java:52) ... 49 more </code></pre> <p>Account.java</p> <pre><code>package de.marcelstuht.nerven2.shared.model; import java.io.Serializable; import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; import javax.validation.constraints.NotNull; import org.apache.commons.codec.digest.DigestUtils; import org.hibernate.Session; import org.hibernate.criterion.*; import de.marcelstuht.nerven2.server.HibernateUtil; @Entity @Table(name = "account") public class Account implements Serializable { private static final long serialVersionUID = 2675108132819989138L; @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") Long id; @NotNull @Column(name = "username", unique = true) String username; @Column(name = "password") String password; @Column(name = "email") String email; protected Session session; public Account() { session = HibernateUtil.getSessionFactory().openSession(); } public Account(Long id) { this.id = id; session = HibernateUtil.getSessionFactory().openSession(); } public Account(Long id, String username, String password, String email) { this.id = id; this.username = username; this.password = password; this.email = email; session = HibernateUtil.getSessionFactory().openSession(); } public void setId(Long newid) { id = newid; } public Long getId() { return id; } public void setUsername(String user) { username = user; } public String getUsername() { return username; } public void setEmail(String mail) { email = mail; } public String getEmail() { return email; } public void setPassword(String newPass) { password = newPass; } public void setNewPassword(String newPass) { password = hashPassword(newPass); } public boolean checkPassword(String pass) { pass = hashPassword(pass); if (password.equals(pass)) return true; else return false; } private String hashPassword(String password) { return DigestUtils.shaHex("wudu390909dfh"+password); } public Account get(Long id) { session.beginTransaction(); Account result = (Account) session.get("account", id); session.getTransaction().commit(); return result; } public Long saveOrUpdate(Account account) { if (account == null) { return null; } session.beginTransaction(); session.saveOrUpdate(account); Long id = (Long) session.getIdentifier(account); session.getTransaction().commit(); return id; } public void delete(Account account) { if (account == null) { return; } session.beginTransaction(); session.delete(account); session.getTransaction().commit(); } public List&lt;Account&gt; getAccountByUsername(String user) { session.beginTransaction(); @SuppressWarnings("unchecked") List&lt;Account&gt; result = session .createCriteria(Account.class) .add(Restrictions.eq("username", user)) .list(); session.getTransaction().commit(); return result; } } </code></pre> <p>HibernateUtil.java</p> <pre><code>package de.marcelstuht.nerven2.server; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.jboss.logging.Logger; public class HibernateUtil { private static final SessionFactory sessionFactory = buildSessionFactory(); protected HibernateUtil() { } private static SessionFactory buildSessionFactory() { try { // Create the SessionFactory from hibernate.cfg.xml Configuration cfg = new Configuration(); SessionFactory sf = cfg.configure().buildSessionFactory(); return sf; } catch (Exception ex) { // Make sure you log the exception, as it might be swallowed Logger.getLogger(HibernateUtil.class).error("Initial SessionFactory creation failed.", ex); throw new ExceptionInInitializerError(ex); } } public static SessionFactory getSessionFactory() { return sessionFactory; } } </code></pre> <p>hibernate.cfg.xml</p> <pre><code>&lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt; &lt;hibernate-configuration&gt; &lt;session-factory&gt; &lt;!-- Database connection settings --&gt; &lt;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt; &lt;property name="connection.url"&gt;jdbc:mysql://127.0.0.1:3306/ba&lt;/property&gt; &lt;property name="connection.username"&gt;*myuser*&lt;/property&gt; &lt;property name="connection.password"&gt;*mypassword*&lt;/property&gt; &lt;!-- JDBC connection pool (use the built-in) --&gt; &lt;property name="connection.pool_size"&gt;1&lt;/property&gt; &lt;!-- SQL dialect --&gt; &lt;property name="dialect"&gt;org.hibernate.dialect.MySQL5InnoDBDialect&lt;/property&gt; &lt;!-- Disable the second-level cache --&gt; &lt;!-- &lt;property name="cache.provider_class"&gt;org.hibernate.cache.internal.NoCacheProvider&lt;/property&gt;--&gt; &lt;!-- Echo all executed SQL to stdout --&gt; &lt;property name="show_sql"&gt;true&lt;/property&gt; &lt;!-- Drop and re-create the database schema on startup --&gt; &lt;property name="hibernate.bytecode.provider"&gt;javassist&lt;/property&gt; &lt;!-- Names the annotated entity class --&gt; &lt;mapping class="de.marcelstuht.nerven2.shared.model.Account"/&gt; &lt;/session-factory&gt; </code></pre> <p></p> <p>I tried both Hibernate 3.6.9 as well as 4.0.1 (in different Eclipse Projects). A screenshot of the JARs I added to the project is available on Skitch: <a href="https://skitch.com/marcelstuht/g7h8h/properties-for-nerven2" rel="noreferrer">https://skitch.com/marcelstuht/g7h8h/properties-for-nerven2</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload