I have hibernate and I would like to decrease the logging that happens in console everytime it runs. I do not have log4j in my application nor do I want to add it in.
Here is an example of the logs I get everytime I run my app
Feb 25, 2014 6:36:41 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
Feb 25, 2014 6:36:41 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.1.Final}
Feb 25, 2014 6:36:41 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Feb 25, 2014 6:36:41 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Feb 25, 2014 6:36:41 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Feb 25, 2014 6:36:41 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Feb 25, 2014 6:36:42 PM 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!
Feb 25, 2014 6:36:42 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Feb 25, 2014 6:36:42 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Feb 25, 2014 6:36:42 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5432/hibernatedb]
Feb 25, 2014 6:36:42 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=Sidney, password=****}
Feb 25, 2014 6:36:42 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
Feb 25, 2014 6:36:42 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
Feb 25, 2014 6:36:43 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
Feb 25, 2014 6:36:43 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
Feb 25, 2014 6:36:43 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Feb 25, 2014 6:36:43 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Feb 25, 2014 6:36:44 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000227: Running hbm2ddl schema export
Feb 25, 2014 6:36:44 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000230: Schema export complete
Here is my 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>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<!-- <property name="connection.url">jdbc:mysql://localhost:3306/hibernateDB</property> -->
<property name="connection.url">jdbc:postgresql://localhost:5432/hibernatedb</property>
<property name="connection.username">**</property>
<property name="connection.password">**</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<!-- <property name="dialect">org.hibernate.dialect.MySQLDialect</property> -->
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">false</property>
<!-- Drop the existing tables and create new one -->
<property name="hbm2ddl.auto">create</property>
<!-- Mention here all the model classes along with their package name -->
<!-- <mapping class="edu.cs157b.hibernate.Student"/> -->
<mapping class="edu.cs157b.hibernate.Doctor"/>
</session-factory>
</hibernate-configuration>
As per your log details I understood that hibernate version is- Hibernate 4.0.4.Final.Since version 4.0, Hibernate has used the JBoss logging library and so even your application does not contain any log4j still hibernate is using JBoss logging provider as default provider.
For more please go through this link:
http://docs.jboss.org/hibernate/orm/4.3/topical/html/logging/Logging.html
Hope this info will help you to understand why logs are still available without any log4j.
You can try to disable all Logger functions using java.util.logging :
private void disableLogging() {
LogManager logManager = LogManager.getLogManager();
Logger logger = logManager.getLogger("");
logger.setLevel(Level.SEVERE); //could be Level.OFF
}
It would affect any other Logger you're using, but in some cases may be useful.
Related
I'm using Hibernate 5.2 with JPA 2.1 Library.Every time I want to run my application it doesn't stop - I have to stop it manually because it's still working. Records are being saved to the database correctly. These are my project files:
Main.java
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("testjpa");
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
Kraj country = new Kraj();
country.setNazwa("ExampleCountry");
em.persist(country);
em.getTransaction().commit();
em.close();
}
**
peristence.xml
**
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="testjpa">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>bazafilmow.model.Aktor</class>
<class>bazafilmow.model.Film</class>
<class>bazafilmow.model.Gatunek</class>
<class>bazafilmow.model.Kraj</class>
<class>bazafilmow.model.Rezyser</class>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/testdb"/>
<property name="javax.persistence.jdbc.user" value="postgres"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="javax.persistence.jdbc.password" value="****"/>
<property name="hibernate.flushMode" value="FLUSH_AUTO" />
<property name="hibernate.hbm2ddl.auto" value="validate" />
</properties>
</persistence-unit>
</persistence>
Output
run:
Jan 03, 2018 11:23:06 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
name: testjpa
...]
Jan 03, 2018 11:23:06 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.12.Final}
Jan 03, 2018 11:23:06 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jan 03, 2018 11:23:06 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Jan 03, 2018 11:23:06 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Jan 03, 2018 11:23:06 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5432/testdb]
Jan 03, 2018 11:23:06 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=postgres, password=****}
Jan 03, 2018 11:23:06 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Jan 03, 2018 11:23:06 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Jan 03, 2018 11:23:06 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL81Dialect
Jan 03, 2018 11:23:07 PM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
Jan 03, 2018 11:23:07 PM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess#45cff11c] 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.
Jan 03, 2018 11:23:07 PM org.hibernate.hql.internal.QueryTranslatorFactoryInitiator initiateService
INFO: HHH000397: Using ASTQueryTranslatorFactory
And it suspends at this moment, there is no BUILD SUCCESSFULL information.
i had a same problem after changing the version it works for me.
I'm getting this error in my Hibernate desktop application:
Initial SessionFactory creation failed.org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
It's not creating SessionFactory and giving this exception:
Executing E:\Vishal\summer\EmpMan\dist\run1432002073\EmpMan.jar using platform C:\Program Files (x86)\Java\jdk1.8.0_131\jre/bin/java
Jul 04, 2017 2:24:35 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.10.Final}
Jul 04, 2017 2:24:35 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jul 04, 2017 2:24:35 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Jul 04, 2017 2:24:35 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Jul 04, 2017 2:24:35 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.h2.Driver] at URL [jdbc:h2:~/EmpMan]
Jul 04, 2017 2:24:35 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=sa, password=****}
Jul 04, 2017 2:24:35 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Jul 04, 2017 2:24:35 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
Initial SessionFactory creation failed.org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
That's it. I'm getting only this much information.
My hibernate.cfg.xml file configuration:
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.h2.Driver</property>
<property name="connection.url">jdbc:h2:~/EmpMan</property>
<property name="connection.username">sa</property>
<property name="connection.password">sa</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.H2Dialect</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.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="hbm2ddl.auto">create</property>
<!-- Names the annotated entity class -->
<mapping class="models.AdminDetails"/>
<mapping class="models.EmployeeDetails" />
<mapping class="models.DepartmentDetails" />
<mapping class="models.DailyDataDetails"/>
</session-factory>
</hibernate-configuration>
Notice:
=> I'm using h2 database and I want to configure embedded database
=> I'm using netbeans and Java8 with hibernate version 5.2.10
=> I'm new to h2 database
=> Where to locate my EmpMan database in my project?
Problem Solved : I have already exist same named database so i changed name and now it's working :) Thank you guys
i am doing hibernate sample in java.below is code used
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="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/serverdata</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<mapping resource="table.hbm.xml"/>
</session-factory>
</hibernate-configuration>
table.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="tabledata" table="tabledata">
<id name="id" column="id" type="ïnteger">
<generator class="assigned"></generator>
</id>
<property name="Name" column="Name" type="string"></property>
</class>
</hibernate-mapping>
inserttable.java
public class Inserttable {
public static void main(String[] args) {
// TODO Auto-generated method stub
Configuration cfg = new Configuration();
cfg.configure("Hibernate.cfg.xml");
SessionFactory sf = cfg.buildSessionFactory();
Session s = sf.openSession();
Transaction tx = s.beginTransaction();
tabledata tab = new tabledata();
tab.setId(1);
tab.setName("mack");
s.save(tab);
s.flush();
tx.commit();
s.close();}
}
i am using mysql database so i am using mysql-connector and below are the following jar used
mysql-connector-java-5.1.38-bin.jar
antlr-2.7.6.jar
cglib-2.2.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar
Hibernate3.jar
Hibernate-jpa-2.0-api-1.0.0.Final.jar
Hibernate-Testing.jar
javassist-3.12.0.GA.jar
jta-1.1.jar
ehcache-1.2.3.jar
slf4j-jdk14-1.5.8.jar
slf4j-api-1.5.8.jar
commons-logging-1.0.4.jar
it shows below error
Dec 26, 2015 6:32:31 PM org.hibernate.annotations.common.Version <clinit>
INFO: Hibernate Commons Annotations 3.2.0.Final
Dec 26, 2015 6:32:31 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.6.4.Final
Dec 26, 2015 6:32:31 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Dec 26, 2015 6:32:31 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : javassist
Dec 26, 2015 6:32:31 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Dec 26, 2015 6:32:31 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: Hibernate.cfg.xml
Dec 26, 2015 6:32:31 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: Hibernate.cfg.xml
Dec 26, 2015 6:32:31 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : firsthb/table.hbm.xml
Dec 26, 2015 6:32:31 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Dec 26, 2015 6:32:31 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: tabledata -> tabledata
Dec 26, 2015 6:32:31 PM org.hibernate.cfg.Configuration applyHibernateValidatorLegacyConstraintsOnDDL
INFO: Hibernate Validator not found: ignoring
Dec 26, 2015 6:32:31 PM org.hibernate.cfg.search.HibernateSearchEventListenerRegister enableHibernateSearch
INFO: Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
Dec 26, 2015 6:32:31 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Dec 26, 2015 6:32:31 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Dec 26, 2015 6:32:31 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Dec 26, 2015 6:32:31 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/serverdata
Dec 26, 2015 6:32:31 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=root, password=****, autocommit=false}
Sat Dec 26 18:32:31 IST 2015 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.
Dec 26, 2015 6:32:32 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Database ->
name : MySQL
version : 5.7.10-log
major : 5
minor : 7
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Driver ->
name : MySQL Connector Java
version : mysql-connector-java-5.1.38 ( Revision: fe541c166cec739c74cc727c5da96c1028b4834a )
major : 5
minor : 1
Dec 26, 2015 6:32:32 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
Dec 26, 2015 6:32:32 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 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: enabled
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Dec 26, 2015 6:32:32 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory createRegionFactory
INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Dec 26, 2015 6:32:32 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Check Nullability in Core (should be disabled when Bean Validation is on): enabled
Dec 26, 2015 6:32:32 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Dec 26, 2015 6:32:32 PM org.hibernate.type.BasicTypeRegistry register
INFO: Type registration [materialized_clob] overrides previous : org.hibernate.type.MaterializedClobType#133e16fd
Dec 26, 2015 6:32:32 PM org.hibernate.type.BasicTypeRegistry register
INFO: Type registration [clob] overrides previous : org.hibernate.type.ClobType#51b279c9
Dec 26, 2015 6:32:32 PM org.hibernate.type.BasicTypeRegistry register
INFO: Type registration [java.sql.Clob] overrides previous : org.hibernate.type.ClobType#51b279c9
Dec 26, 2015 6:32:32 PM org.hibernate.type.BasicTypeRegistry register
INFO: Type registration [wrapper_characters_clob] overrides previous : org.hibernate.type.CharacterArrayClobType#1ad282e0
Dec 26, 2015 6:32:32 PM org.hibernate.type.BasicTypeRegistry register
INFO: Type registration [materialized_blob] overrides previous : org.hibernate.type.MaterializedBlobType#7f416310
Dec 26, 2015 6:32:32 PM org.hibernate.type.BasicTypeRegistry register
INFO: Type registration [wrapper_materialized_blob] overrides previous : org.hibernate.type.WrappedMaterializedBlobType#1cab0bfb
Dec 26, 2015 6:32:32 PM org.hibernate.type.BasicTypeRegistry register
INFO: Type registration [characters_clob] overrides previous : org.hibernate.type.PrimitiveCharacterArrayClobType#5e955596
Dec 26, 2015 6:32:32 PM org.hibernate.type.BasicTypeRegistry register
INFO: Type registration [blob] overrides previous : org.hibernate.type.BlobType#50de0926
Dec 26, 2015 6:32:32 PM org.hibernate.type.BasicTypeRegistry register
INFO: Type registration [java.sql.Blob] overrides previous : org.hibernate.type.BlobType#50de0926
Exception in thread "main" org.hibernate.MappingException: entity class not found: tabledata
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:125)
at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:191)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:67)
at org.hibernate.tuple.entity.EntityMetamodel.<init> (EntityMetamodel.java:135)
at org.hibernate.persister.entity.AbstractEntityPersister.<init> (AbstractEntityPersister.java:485)
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:286)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872)
at firsthb.Inserttable.main(Inserttable.java:16)
Caused by: java.lang.ClassNotFoundException: tabledata
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:122)
... 9 more
Please help me to know whats the problem in my code or is it about jar files added.let me know,any help is appreciated.
EDIT: Also replace with in tabledata.hbm.xml after this it works.I think this will be good example for hibernate learning beginners.
Your folder does follow the right conventions
Resource files should be under src/main/resources
java files under src/main/java
Though its not mandatory to follow but you should as some of your issues will automatically go away and then you are moving towards convention over configuration. Otherwise you can do below as hfg file will be able to search the hbm file from right folder
In your file Hibernate.cfg.xml add this
<mapping resource="firsthb/table.hbm.xml"/>
I am new in hibernate
I have a UserDAO class and a method to determine whether user exists in a specific table or not.
This is my users table in hb3 database:
And this is my class:
public static void main(String[] args) {
System.out.println(userExistsinDB("ABC"));
}
public static boolean userExistsinDB(String username) {
String queryStr = "Select * from users where username=" + username; // since username is unique
SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
Query query = session.createSQLQuery(queryStr);
System.out.println(query.getFirstResult());
session.getTransaction().commit();
session.close();
sessionFactory.close();
return false;
}
But the result is null in query.getFirstResult() , Why?
I have ABC username in users table.
Hibernate config file:
<?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.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hb3</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">2323</property>
<property name="hibernate.show_sql">true</property>
<mapping class="sajjad.htlo.User"/>
</session-factory>
</hibernate-configuration>
Result:
Feb 20, 2015 1:19:23 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
Feb 20, 2015 1:19:23 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.1.Final}
Feb 20, 2015 1:19:23 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Feb 20, 2015 1:19:23 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Feb 20, 2015 1:19:23 AM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Feb 20, 2015 1:19:23 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Feb 20, 2015 1:19:23 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!
Feb 20, 2015 1:19:23 AM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Feb 20, 2015 1:19:23 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Feb 20, 2015 1:19:23 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/hb3]
Feb 20, 2015 1:19:23 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=root, password=****}
Feb 20, 2015 1:19:23 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
Feb 20, 2015 1:19:23 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Feb 20, 2015 1:19:23 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Feb 20, 2015 1:19:23 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Feb 20, 2015 1:19:23 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
null
Feb 20, 2015 1:19:24 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH000030: Cleaning up connection pool [jdbc:mysql://localhost:3306/hb3]
false
Try this:
org.hibernate.Query query = session.createQuery("from users where username = :username");
query.setParameter("username", username);
query.uniqueResult();
You should use parameterized query. It returns null because string literals should be enclosed by quote notation.
I am desperate trying to connect to a DB2 database via hibernate. Problem is here, I know, where the error comes from but I can't solve it or rather don't understand it. Maybe you can help me fix this problem. I would be very grateful!
The following code shows my 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>
<property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</property>
<property name="hibernate.connection.url">jdbc:db2://db2.example.com:50001/databasename</property>
<property name="hibernate.connection.username">mydbuser</property>
<property name="hibernate.connection.password">mydbpass</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<mapping class="media.definitions.Product" />
</session-factory>
</hibernate-configuration>
This following code is a class which I've built by a tutorial:
package media.frontend;
import org.hibernate.SessionFactory;
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;
static {
Configuration cfg = new Configuration().configure("hibernate.cfg.xml");
StandardServiceRegistryBuilder sb = new StandardServiceRegistryBuilder();
sb.applySettings(cfg.getProperties());
StandardServiceRegistry standardServiceRegistry = sb.build();
sessionFactory = cfg.buildSessionFactory(standardServiceRegistry);
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
And the following error comes immediately when I start the program (which only tries to catch information of a single column). I've pasted the whole output:
Aug 14, 2014 5:45:45 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
Aug 14, 2014 5:45:45 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.6.Final}
Aug 14, 2014 5:45:45 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Aug 14, 2014 5:45:45 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Aug 14, 2014 5:45:45 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: hibernate.cfg.xml
Aug 14, 2014 5:45:45 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: hibernate.cfg.xml
Aug 14, 2014 5:45:45 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Aug 14, 2014 5:45:45 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Aug 14, 2014 5:45:45 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [com.ibm.db2.jcc.DB2Driver] at URL [jdbc:db2://anger.informatik.uni-leipzig.de:50001/PRAK14B]
Aug 14, 2014 5:45:45 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=dbprak12, password=****}
Aug 14, 2014 5:45:45 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
Aug 14, 2014 5:45:45 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 10 (min=1)
Aug 14, 2014 5:45:45 PM org.hibernate.engine.jdbc.internal.JdbcServicesImpl configure
WARN: HHH000341: Could not obtain connection metadata : DatabaseMetaData information is not known for server DB2/SUNX8664SQL10010 by this version of JDBC driver
Aug 14, 2014 5:45:45 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000422: Disabling contextual LOB creation as connection was null
Exception in thread "main" java.lang.ExceptionInInitializerError
at media.frontend.HibernateTest.main(HibernateTest.java:15)
Caused by: java.lang.NullPointerException
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:244)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
at media.frontend.HibernateUtil.<clinit>(HibernateUtil.java:17)
... 1 more
Thanks in advance for your help!
Greets,
Luke
I was facing similar issue in my code. Then i tried updating the recent versions of DB2 jars into my server and the code started working. Try to update your DB2 jar.