Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7248983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:13:09+00:00 2026-05-28T22:13:09+00:00

I have a serious problem with hibernate. I followed various books und online tutorials,

  • 0

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

SessionFactory sf = cfg.configure().buildSessionFactory();

My Tomcat log says the following:

Caused by: java.lang.ExceptionInInitializerError
at de.marcelstuht.nerven2.server.HibernateUtil.buildSessionFactory(HibernateUtil.java:23)
at de.marcelstuht.nerven2.server.HibernateUtil.<clinit>(HibernateUtil.java:8)
at de.marcelstuht.nerven2.shared.model.Account.<init>(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.<init>(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.<init>(EntityMetamodel.java:143)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:498)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(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.<init>(Account.java:52)
... 49 more

Account.java

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<Account> getAccountByUsername(String user) {
    session.beginTransaction();

    @SuppressWarnings("unchecked")
    List<Account> result = session
            .createCriteria(Account.class)
            .add(Restrictions.eq("username", user))
            .list();
    session.getTransaction().commit();

    return result;
}

}

HibernateUtil.java

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;
}
}

hibernate.cfg.xml

<!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">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://127.0.0.1:3306/ba</property>
    <property name="connection.username">*myuser*</property>
    <property name="connection.password">*mypassword*</property>

    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>

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

    <!-- Disable the second-level cache  -->
    <!-- <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>-->

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

    <!-- Drop and re-create the database schema on startup -->        
    <property name="hibernate.bytecode.provider">javassist</property>

    <!-- Names the annotated entity class -->
    <mapping class="de.marcelstuht.nerven2.shared.model.Account"/>

</session-factory>

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: https://skitch.com/marcelstuht/g7h8h/properties-for-nerven2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:13:10+00:00Added an answer on May 28, 2026 at 10:13 pm

    aused by: java.lang.NullPointerException
    at de.marcelstuht.nerven2.shared.model.Account.(Account.java:52)
    … 49 more

    Remove anything from your constructor in Account. You have a circular dependency. And Hibernate uses the public no args consructor for its beans

    1. HibernateUtil loads
    2. That forces the static to run buildSessionFactory
    3. Hibernate instantiates Account via no args
    4. That in turn calls HibernateUtil…..

    Trust me: public no arg constructor with NO code, except POJO setters. Nothing else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing ESME using logica smpp lib , but have a serious problem
I have a real serious problem with maple, I can't get it to display
I am making a scripting language but I have a serious problem. I need
I have a serious problem. One of our servers crashed. Now I reinstalled the
I am new to python and I have a serious problem that I cannot
Woah, I have this serious problem with jquery datatables plugin. I have a table
Ok guys, I have a serious problem with this. I have a static class
I have a serious performance problem. I have a database with (related to this
I have a serious problem in my app. I wrote a facebook like instant
I have this serious problem. I have an enumeration within 2 namespaces like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.