I really need close the sessionFactory? - java

To resolve my problem I use this code below. But I dont think this is right...
HibernateFactory.buildSessionFactory();
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
#Override
public void handle(WindowEvent event) {
HibernateFactory.closeFactory();
}
});
Thats my dependencies
Jar files
And my hibernate.cfg
<?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>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/ClinicaVet?UseTimezone=true&serverTimezone=UTC</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">jailbreak</property>
<property name="current_session_context_class">thread</property>
<!-- Disable the second level cache -->
<property
name="cache.provider_class">org.hibernate.cache.internall.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="hbm2dd1">update</property>
<mapping resource="com/arthurpdj/entity/Agendamento.hbm.xml"/>
<mapping resource="com/arthurpdj/entity/Animal.hbm.xml"/>
<mapping resource="com/arthurpdj/entity/Cliente.hbm.xml"/>
<mapping resource="com/arthurpdj/entity/Examinacao.hbm.xml"/>
<mapping resource="com/arthurpdj/entity/Exame.hbm.xml"/>
<mapping resource="com/arthurpdj/entity/Vacinacao.hbm.xml"/>
<mapping resource="com/arthurpdj/entity/Notificacoes.hbm.xml"/>
<mapping resource="com/arthurpdj/entity/Vacina.hbm.xml"/>
<mapping resource="com/arthurpdj/entity/Atendimento.hbm.xml"/>
<mapping resource="com/arthurpdj/entity/Pagamento.hbm.xml"/>
</session-factory> </hibernate-configuration>
And My HibernateUtil class ( I already try to without ServiceRegistry.. same problem.. )
public class HibernateUtil {
private static SessionFactory factory = null;
private static Configuration conf;
private static ServiceRegistry serviceRegistry;
private static SessionFactory buildSessionFactory() {
try{
conf = new Configuration();
conf.configure("com/arthurpdj/database/hibernate.cfg.xml");
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
conf.getProperties()).build();
System.out.println("Configurou");
factory = conf.buildSessionFactory(serviceRegistry);
System.out.println("construi");
return factory;
} catch(Throwable ex) {
ex.printStackTrace();
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory(){
if(factory ==null) {
factory = buildSessionFactory();
}
return factory;
}
}
Log
fev 02, 2017 3:05:14 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.7.Final}
fev 02, 2017 3:05:14 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
fev 02, 2017 3:05:14 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
fev 02, 2017 3:05:15 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
fev 02, 2017 3:05:15 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/ClinicaVet?UseTimezone=true&serverTimezone=UTC]
fev 02, 2017 3:05:15 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
fev 02, 2017 3:05:15 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
fev 02, 2017 3:05:15 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Thu Feb 02 15:05:16 BRST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
fev 02, 2017 3:05:16 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Main Class
#Override
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("view/FXMLLogin.fxml"));
Scene scene = new Scene(root, 424, 331);
primaryStage.setMaximized(false);
primaryStage.setResizable(false);
primaryStage.setTitle("Clinica Veterinária BarraVet");
primaryStage.setScene(scene);
primaryStage.show();
HibernateFactory.buildSessionFactory();
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
#Override
public void handle(WindowEvent event) {
HibernateFactory.closeFactory();
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}

Just initialize using this:
{
//creating configuration object
Configuration cfg=new Configuration();
cfg.configure("hibernate.cfg.xml");//populates the data of the configuration file
//creating seession factory object
SessionFactory factory=cfg.buildSessionFactory();
//creating session object
Session session=factory.openSession();
//creating transaction object
Transaction t=session.beginTransaction();
//Your code of reading/writing to database here.....
t.commit();//transaction is committed
session.close();
System.out.println("successful transaction");
}
}
Thats the safest method...Hope this helps

#Akshay, thanks for trying. I solved my problem using the c3p0 connection pool

Related

Cannot connect to Informix using Hibernate

I'm trying to connect to Informix database using Hibernate 5.2.10, but the program doesn't respond and gets stuck without throwing any error message.
I can't find anything from the console . Any suggest on what mistake I made? I'm new to Hibernate
hibernate.cfg.xml
<property name="connection.driver_class">com.informix.jdbc.IfxDriver</property>
<property name="connection.url">jdbc:informixsqli://****:1528/****:informixserver=*****</property>
<property name="connection.username">*****</property>
<property name="connection.password">*****</property>
Console:
Sep 17, 2017 11:05:55 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.10.Final}
Sep 17, 2017 11:05:55 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Sep 17, 2017 11:06:05 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Sep 17, 2017 11:06:05 AM org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
INFO: HHH010002: C3P0 using driver: com.informix.jdbc.IfxDriver at URL: jdbc:informix-sqli://d7uat:1528/d7main:informixserver=uatserver
Sep 17, 2017 11:06:05 AM org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
INFO: HHH10001001: Connection properties: {user=******, password=****}
Sep 17, 2017 11:06:05 AM org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
INFO: HHH10001003: Autocommit mode: false
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Sep 17, 2017 11:06:07 AM org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
INFO: HHH10001007: JDBC isolation level: <unknown>
Sep 17, 2017 11:06:08 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.InformixDialect
Sep 17, 2017 11:06:14 AM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess#7a0ef219] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
HibernateUtil
private static final SessionFactory sessionFactory = buildSessionFactory();
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
private static SessionFactory buildSessionFactory(){
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build();
try {
return new
MetadataSources(registry).buildMetadata().buildSessionFactory();
}
catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
StandardServiceRegistryBuilder.destroy( registry );
throw new ExceptionInInitializerError(ex);
}
}
InformixTest
public static CustomerInvoice lookupInvoice(String invoiceNumber){
Session session = null;
List<CustomerInvoice> customerInvoiceList = new ArrayList<CustomerInvoice>();
CustomerInvoice customerInvoice = null;
try {
session = HibernateUtil.getSessionFactory().openSession();
Query query = session.createQuery(invoiceByNumber);
query.setParameter("invoiceNumber", invoiceNumber+"%");
customerInvoiceList = ((org.hibernate.query.Query) query).list();
} catch (Exception e) {
e.printStackTrace();
session.close();
} finally {
if (session != null && session.isOpen()) {
session.close();
}
}
if(customerInvoiceList.size()>0){
customerInvoice = customerInvoiceList.get(0);
}
return customerInvoice;
}
I did a quick test with 5.2 and the latest jdbc driver and it appears to work fine for me. I'm using your HiberanateUtil and a similar Hibernate config file:
D:\Infx\work\Hibernate>java list
Sep 18, 2017 10:53:49 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.11.Final}
Sep 18, 2017 10:53:49 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Sep 18, 2017 10:53:49 AM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead. Support for obsolete DTD/XSD namespaces may be removed at any time.
Sep 18, 2017 10:53:50 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Sep 18, 2017 10:53:50 AM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead. Support for obsolete DTD/XSD namespaces may be removed at any time.
Sep 18, 2017 10:53:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Sep 18, 2017 10:53:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.informix.jdbc.IfxDriver] at URL [jdbc:informix-sqli://420ito:9088/stores7:INFORMIXSERVER=ids1210;user=informix;password=dummy;]
Sep 18, 2017 10:53:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {}
Sep 18, 2017 10:53:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Sep 18, 2017 10:53:51 AM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Sep 18, 2017 10:53:52 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.InformixDialect
Sep 18, 2017 10:53:53 AM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess#37ebc9d8] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
Sep 18, 2017 10:53:55 AM org.hibernate.hql.internal.QueryTranslatorFactoryInitiator initiateService
INFO: HHH000397: Using ASTQueryTranslatorFactory
Hibernate: select state0_.id as id1_0_, state0_.code as code2_0_, state0_.sname as sname3_0_, state0_.next_state_id as next_sta4_0_ from States state0_ order by state0_.id asc
test, test
test, test
Sep 18, 2017 10:53:55 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:informix-sqli://420ito:9088/stores7:INFORMIXSERVER=ids1210;user=informix;password=dummy;]
D:\Infx\work\Hibernate>
Only way I get something like a 'hang' is if I get an exception during the open session(). I forced one compiling the method with an old Hibernate version library (3.x) which doesn't have 'classic' methods:
D:\Infx\work\Hibernate>java list
Sep 18, 2017 10:54:42 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.11.Final}
Sep 18, 2017 10:54:42 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Sep 18, 2017 10:54:42 AM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead. Support for obsolete DTD/XSD namespaces may be removed at any time.
Sep 18, 2017 10:54:42 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Sep 18, 2017 10:54:42 AM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead. Support for obsolete DTD/XSD namespaces may be removed at any time.
Sep 18, 2017 10:54:44 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Sep 18, 2017 10:54:44 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.informix.jdbc.IfxDriver] at URL [jdbc:informix-sqli://420ito:9088/stores7:INFORMIXSERVER=ids1210;user=informix;password=dummy;]
Sep 18, 2017 10:54:44 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {}
Sep 18, 2017 10:54:44 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Sep 18, 2017 10:54:44 AM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Sep 18, 2017 10:54:44 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.InformixDialect
Sep 18, 2017 10:54:46 AM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess#37ebc9d8] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;
at list.main(list.java:12)
....
....
....
As yours, 'last' INFO message is "Connection obtained from JdbcConnectionAccess" , but after that I'm also getting the nosuchmethod exception. I have to press control+c to get out.
Maybe your exceptions are been sent somewhere else ;)
EDIT
This is the code I'm using to test it directly from the console, should be everything you need to run it.
D:\Infx\work\Hibernate>cat set5.cmd
#echo off
set CLASSPATH=
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\javassist-3.20.0-GA.jar
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\dom4j-1.6.1.jar
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\hibernate-jpa-2.1-api-1.0.0.Final.jar
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\hibernate-core-5.2.11.Final.jar
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\hibernate-commons-annotations-5.0.1.Final.jar
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\ifxjdbc.jar
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\jta-1.1.jar
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\classmate-1.3.0.jar
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\jboss-logging-3.3.0.Final.jar
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\antlr-2.7.7.jar
set CLASSPATH=%CLASSPATH%;.
D:\Infx\work\Hibernate>cat hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!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.informix.jdbc.IfxDriver
</property>
<property
name="connection.url">jdbc:informix-sqli://420ito:9088/stores7:INFORMIXSERVER=ids1210;user=informix;password=dummy;
</property>
<property
name="dialect">org.hibernate.dialect.InformixDialect
</property>
<property name="hibernate.show_sql">true
</property>
<property
name="current_session_context_class">thread
</property>
<property name="hbm2ddl.auto">update</property>
<mapping resource="State.hbm.xml"/>
</session-factory>
</hibernate-configuration>
D:\Infx\work\Hibernate>cat State.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="State"
table="States">
<id
name="id"
column="id">
<generator class="increment"/>
</id>
<property
name="code"
column="code"/>
<property
name="sname"
column="sname"/>
<many-to-one
name="nextState"
cascade="all"
column="next_state_id"/>
</class>
</hibernate-mapping>
D:\Infx\work\Hibernate>cat HibernateUtil.java
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
public class HibernateUtil { private static final SessionFactory sessionFactory = buildSessionFactory();
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
private static SessionFactory buildSessionFactory(){
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build();
try {
return new
MetadataSources(registry).buildMetadata().buildSessionFactory();
}
catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
StandardServiceRegistryBuilder.destroy( registry );
throw new ExceptionInInitializerError(ex);
}
}
public static void shutdown() {
// Close caches and connection pools
getSessionFactory().close();
}
}
D:\Infx\work\Hibernate>cat create.java
import java.util.*;
import org.hibernate.*;
import javax.persistence.*;
public class create {
public static void main(String[] args) {
java.util.logging.Logger.getLogger("org.hibernate").setLevel(java.util.logging.Level.FINEST );
java.util.logging.Logger.getLogger("org.hibernate").setLevel(java.util.logging.Level.SEVERE );
Session Session = HibernateUtil.getSessionFactory().openSession();
Transaction Transaction = Session.beginTransaction();
State myState = new State();
myState.setcode(args[0]);
myState.setsname(args[1]);
Long stateId = (Long) Session.save(myState);
System.out.println("Stated added: "+myState.getcode()+", "+myState.getsname() );
Transaction.commit();
Session.close();
// Shutting down the application
HibernateUtil.shutdown();
}
}
D:\Infx\work\Hibernate>cat list.java
import java.util.*;
import org.hibernate.*;
import javax.persistence.*;
public class list {
public static void main(String[] args) {
java.util.logging.Logger.getLogger("org.hibernate").setLevel(java.util.logging.Level.FINEST );
java.util.logging.Logger.getLogger("org.hibernate").setLevel(java.util.logging.Level.SEVERE );
Session newSession = HibernateUtil.getSessionFactory().openSession();
Transaction newTransaction = newSession.beginTransaction();
List states = newSession.createQuery("from State order by id asc").list();
for ( Iterator iter = states.iterator();
iter.hasNext(); ) {
State state = (State) iter.next();
System.out.println(state.getcode() +", " + state.getsname() );
}
newTransaction.commit();
newSession.close();
HibernateUtil.shutdown();
}
}
D:\Infx\work\Hibernate>
create.java will insert a new row, and list.java will select from the 'State' table:
D:\Infx\work\Hibernate>java com.informix.jdbc.Version
IBM Informix JDBC Driver Version 4.10.JC9
D:\Infx\work\Hibernate>javac create.java
D:\Infx\work\Hibernate>javac list.java
D:\Infx\work\Hibernate>java create test1 test2
Hibernate: select max(id) from States
Stated added: test1, test2
Hibernate: insert into States (code, sname, next_state_id, id) values (?, ?, ?, ?)
D:\Infx\work\Hibernate>java list
Hibernate: select state0_.id as id1_0_, state0_.code as code2_0_, state0_.sname as sname3_0_, state0_.next_state_id as next_sta4_0_ from States state0_ order by state0_.id asc
test, test
test, test
test1, test2
D:\Infx\work\Hibernate>
but I guess it shouldn't be much different than what you already have.
Thanks for trying to help me out. The issue got resolved after I removed this property from hibernate config file.
<property name="hbm2ddl.auto">update</property>

Java hibernate throws Exception at boot

I'm working on a project with Hibernate now but I get an error when running my project.
On server.java (my entry point) I got this:
private static HibernateUtil hibernateUtil;
And in my entry point:
hibernateUtil = new HibernateUtil();
This is my HibernateUtil class:
public class HibernateUtil {
private SessionFactory sessionFactory;
public HibernateUtil() {
StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build();
try {
sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
}
catch (Exception e) {
StandardServiceRegistryBuilder.destroy( registry );
}
}
public SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Now my Hibernate.cf.xml:
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">123</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/dynamicdb</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="show_sql">false</property>
<property name="connection.pool_size">1</property>
</session-factory>
And now this is the error I get:
Jun 18, 2016 1:17:17 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.0.Final}
Jun 18, 2016 1:17:17 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jun 18, 2016 1:17:17 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jun 18, 2016 1:17:18 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Jun 18, 2016 1:17:18 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Jun 18, 2016 1:17:18 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.cj.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/dynamicdb]
Jun 18, 2016 1:17:18 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
Jun 18, 2016 1:17:18 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Jun 18, 2016 1:17:18 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
Jun 18, 2016 1:17:18 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:mysql://localhost:3306/dynamicdb]
Jun 18, 2016 1:17:18 PM org.hibernate.service.internal.AbstractServiceRegistryImpl stopService
INFO: HHH000369: Error stopping service [class org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] : java.lang.NullPointerException
I'm running Eclipse mars 2 on Mac OS X 10.10 with MAMP. MySQL is running and the database user and database exists and the password is correct. What's the problem?
I have the same problem like you. It seems that we both copy the code from Hibernate Official code samples. I think maybe it's bug of mysql connecotrj 6.0.After I add throw statement to the catch statement:
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure()
.build();
try {
sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
} catch (Exception e) {
StandardServiceRegistryBuilder.destroy(registry);
throw new RuntimeException(e);
}
And I found the origin exception:
Caused by: com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
This case doesn't appear in mysql connectorj 5.1
So, there are two solutions:switch mysql jdbc drivers to 5.1 or add timezone argument to jdbc url string like this. In hibernate.cfg.xml file don't forget to change & to &
I got the same issue when my mapping file contained one column twice
<property column="STATE" name="state" type="java.lang.String" not-null="true"/>
<property column="BRANCH" name="branch" type="java.lang.String" not-null="true"/>
<property column="COUNTRY" name="country" type="java.lang.String" not-null="true"/>
<property column="STATE" name="state" type="java.lang.String" not-null="true"/>
So once I changed one state to appropriate property e.g.
<property column="SITE" name="site" type="java.lang.String" not-null="true"/>
The issue was solved.
So be careful with your mappings
In my case, I was using Netbeans and had my entities generated using Netbeans only.
after fiddling with mysql and hibernate-core jar versions, after commenting #NamedQueries fixed it for me.
For others who may still encounter this issue, the database provided in the connection URL needs to exist, in this case, we need to ensure the database dynamicdb exists. I had the same issue and this fixed it.

Hibernate working with queries

Started to learn hibernate. Doing everything by tutorial, but when I try to do simple select, nothing happens. Сan't understand what the problem is.
Logs:
мар 28, 2016 12:54:44 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.1.0.Final}
мар 28, 2016 12:54:44 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
мар 28, 2016 12:54:44 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
мар 28, 2016 12:54:45 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
мар 28, 2016 12:54:45 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
мар 28, 2016 12:54:45 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/taskboard]
мар 28, 2016 12:54:45 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
мар 28, 2016 12:54:45 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
мар 28, 2016 12:54:45 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
мар 28, 2016 12:54:45 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
мар 28, 2016 12:54:45 PM org.hibernate.validator.internal.util.Version <clinit>
INFO: HV000001: Hibernate Validator 5.2.4.Final
мар 28, 2016 12:54:45 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:mysql://localhost:3306/taskboard]
User.java
#Entity
#Table(name="Users")
public class User {
#Id
#Column(name="id_user")
private Long id;
#Column(name="first_name")
private String firstName;
#Column(name="last_name")
private String lastName;
#Column(name="login")
private String login;
#Column(name="password")
private String password;
}//get&set
Main.java
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
List<User> users = null;
try {
session.beginTransaction();
Criteria criteria = session.createCriteria(User.class);
users = criteria.list();
session.getTransaction().commit();
} catch (Exception e) {
session.getTransaction().rollback();
e.printStackTrace();
} finally {
session.close();
sessionFactory.close();
}
for (User user: users) {
System.out.println(user.toString());
}
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>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/taskboard</property>
<property name="connection.username">root</property>
<property name="connection.password">1234</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<mapping class="User" />
</session-factory>
</hibernate-configuration>
HibernateUtil.java
public class HibernateUtil {
private static SessionFactory sessionFactory = null;
static {
Configuration cfg = new Configuration().configure();
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
.applySettings(cfg.getProperties());
sessionFactory = cfg.buildSessionFactory(builder.build());
}
public static SessionFactory getSessionFactory(){
return sessionFactory;
}
}
As far as I remember, the newer version of hibernate do not support <mapping class= .../> in the hibernate configuration file any longer.
Can you remove that and instead try with
cfg.addAnnotatedClass(User.class) in your HibernateUtil static block.
On a different note, you may want to consider using the latest approach of building the sessionFactory as Configuration way is deprecated. Refer to Native Bootstrapping section for more information.
May be nothing in data base for Users table.First Insert some data. Then check.

Hibernate Exception in thread "main" java.lang.ExceptionInInitializerError

I am brand new to Hibernate so please go easy on me!
I am just trying to open and close a hibernate session as follows:
Program.java is as follows:
package com.simpleprogrammer;
import org.hibernate.Session;
public class Program {
public static void main(String[] args) {
System.out.println("Hello world!");
Session session = HibernateUtilities.getSessionFactory().openSession();
session.close();
}
}
and my HibernateUtilities.java file is as follows:
package com.simpleprogrammer;
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
public class HibernateUtilities {
private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;
static {
try
{
Configuration configuration = new Configuration().configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}
catch (HibernateException exception)
{
System.out.println("Problem creating session factory");
}
}
public static SessionFactory getSessionFactory()
{
return sessionFactory;
}
}
and finally my hibernate.cfg.xml file is as follows:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.password">password</property>
<property name="connection.url">jdbc:mysql://localhost:3306</property>
<property name="connection.username">appuser</property>
<property name="connection.default_schema">protien_tracker</property>
<property name="connection.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.show_sql">true</property>
<!-- <property name="hbm2ddl.auto">update</property> -->
</session-factory>
</hibernate-configuration>
When I try to run this, I am getting a null pointer exception, stack trace is as follows:
"C:\Program Files\Java\jdk1.8.0_45\bin\java" -Didea.launcher.port=7537 "-Didea.launcher.bin.path=C:\Users\John Stafford\AppData\Roaming\JetBrains\IntelliJ IDEA 15.0.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_45\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_45\jre\lib\rt.jar;C:\Java\intellij\ProtienTracker\out\production\ProtienTracker;C:\Java\intellij\ProtienTracker\lib\hibernate-jpa-2.0-api-1.0.1.Final.jar;C:\Java\intellij\ProtienTracker\lib\antlr-2.7.7.jar;C:\Java\intellij\ProtienTracker\lib\hibernate-commons-annotations-4.0.2.Final.jar;C:\Java\intellij\ProtienTracker\lib\jboss-logging-3.1.0.GA.jar;C:\Java\intellij\ProtienTracker\lib\dom4j-1.6.1.jar;C:\Java\intellij\ProtienTracker\lib\jboss-transaction-api_1.1_spec-1.0.1.Final.jar;C:\Java\intellij\ProtienTracker\lib\javassist-3.15.0-GA.jar;C:\Java\intellij\ProtienTracker\lib\hibernate-core-4.2.2.Final.jar;C:\Java\intellij\ProtienTracker\lib\mysql-connector-java-5.0.4-bin.jar;C:\Users\John Stafford\AppData\Roaming\JetBrains\IntelliJ IDEA 15.0.3\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.simpleprogrammer.Program
Hello world!
Jan 20, 2016 9:03:37 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
Jan 20, 2016 9:03:37 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.2.Final}
Jan 20, 2016 9:03:37 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jan 20, 2016 9:03:37 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jan 20, 2016 9:03:37 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Jan 20, 2016 9:03:37 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Jan 20, 2016 9:03:38 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Jan 20, 2016 9:03:38 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Jan 20, 2016 9:03:38 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
Jan 20, 2016 9:03:38 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: false
Jan 20, 2016 9:03:38 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306]
Jan 20, 2016 9:03:38 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=appuser, password=****, dialect=org.hibernate.dialect.MySQLDialect, show_sql=true, default_schema=protien_tracker}
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.simpleprogrammer.Program.main(Program.java:11)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.NullPointerException
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:214)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:242)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:117)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1797)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1755)
at com.simpleprogrammer.HibernateUtilities.<clinit>(HibernateUtilities.java:18)
... 6 more
Process finished with exit code 1
Does anybody know what I have done wrong here?
Following is an example for creating session: HibernateUtil
public class HibernateUtil {
private static SessionFactory sessionFactory;
public static SessionFactory getSessionFactory() {
if(sessionFactory==null)
{
try{
sessionFactory = new AnnotationConfiguration().
configure().
//addPackage("com.xyz") //add package if used.
addAnnotatedClass(User.class).
buildSessionFactory();
}catch (Throwable ex) {
System.err.println("Failed to create sessionFactory object." + ex);
throw new ExceptionInInitializerError(ex);
}
}
return sessionFactory;
}
}
Using session
public class Dao {
public void save(Object obj) {
SessionFactory sessionFactory=HibernateUtil.getSessionFactory();
Session session=sessionFactory.openSession();
try{
session.beginTransaction();
session.save(obj);
session.getTransaction().commit();
session.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Make sure you have jdbc jar in lib
If you are using Hibernate 4.3++, change the following lines in HibernateUtilities class.
configuration = new Configuration();
configuration.configure("hibernate.cfg.xml");
StandardServiceRegistryBuilder serviceBuilder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
sessionFactory = configuration.buildSessionFactory(serviceBuilder.build());
And make the following changes to hibernate.cfg.xml
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/protien_tracker</property>
<property name="connection.username">appuser</property>
<property name="connection.password">password</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>

Hibernate cant test my session, it's null

Hi im using eclipse this hibernate update.
i have this config:
<?xml version="1.0" encoding="UTF-8"?>
<!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="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.default_schema">protein_tracker</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
</session-factory>
</hibernate-configuration>
i have this class that has the basics to start hibernate:
package com.simpleprogramer;
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.ServiceRegistry;
public class HibernateUtilities {
private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;
static{
try{
Configuration configuration = new Configuration().configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}
catch(HibernateException exeption)
{
System.out.println("Problem creating session factory!");
}
}
public static SessionFactory getSessionFactory(){
return sessionFactory;
}
}
and main that test hibernate session, and i don't know were is the null:
package com.simpleprogramer;
import org.hibernate.Session;
public class program {
public static void main(String[] args) {
System.out.println("Hola mundo");
Session session = HibernateUtilities.getSessionFactory().openSession();
session.close();
}
}
getting this error from console:
Hola mundo
oct 01, 2013 2:12:31 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
oct 01, 2013 2:12:31 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.6.Final}
oct 01, 2013 2:12:31 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
oct 01, 2013 2:12:31 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
oct 01, 2013 2:12:31 AM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
oct 01, 2013 2:12:31 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
oct 01, 2013 2:12:31 AM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
oct 01, 2013 2:12:31 AM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
oct 01, 2013 2:12:31 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Problem creating session factory!
Exception in thread "main" java.lang.NullPointerException
at com.simpleprogramer.program.main(program.java:9)
Hi there, thank you for your advice exeption.printStacktrace(System.out);. I figure out that my jdbc driver was not loaded, and then realized that it wasn't loaded at all on the proyect (i thought that the config autoload no matter what or were the driver is). So i downloaded the corresponding jar and it works. Thanks for your advice!

Categories

Resources