I'm trying to get information out of an existing database.
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.url">jdbc:postgresql://localhost:5432/ecm_politik_mt</property>
<property name="connection.username">ecm</property>
<property name="connection.password">ecm</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<mapping class="com.database.Survey_question" />
</session-factory>
</hibernate-configuration>
The entity I try to map:
package com.database;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name = "survey_question")
public class Survey_question implements Serializable {
#Id
#GeneratedValue
#Column(name = "id")
private Integer id;
#Column(name = "freetext")
private boolean freetext;
#Column(name = "idx")
private Integer idx;
#Column(name = "mandatory")
private boolean mandatory;
#Column(name = "multiplechoice")
private boolean multiplechoice;
#Column(name = "title")
private String title;
#Column(name = "sheet_id")
private Integer sheet_id;
public Survey_question() {
}
public boolean getFreetext() {
return freetext;
}
public void setFreetext(boolean freetext) {
this.freetext = freetext;
}
public Integer getIdx() {
return idx;
}
public void setIdx(Integer idx) {
this.idx = idx;
}
public boolean getMandatory() {
return mandatory;
}
public void setMandatory(boolean mandatory) {
this.mandatory = mandatory;
}
public boolean getMultiplechoice() {
return multiplechoice;
}
public void setMultiplechoice(boolean multiplechoice) {
this.multiplechoice = multiplechoice;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Integer getSheet_id() {
return sheet_id;
}
public void setSheet_id(Integer sheet_id) {
this.sheet_id = sheet_id;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
#Override
public String toString() {
return "Question [freetext=" + freetext + ", idx=" + idx
+ ", mandatory=" + mandatory + ", multiplechoice="
+ multiplechoice + ", title=" + title + ", sheet_id="
+ sheet_id + "]";
}
}
The query:
Query query = session.createQuery("from Survey_question");
List<Survey_question> list = query.list();
Iterator<Survey_question> iter = list.iterator();
while (iter.hasNext()) {
Survey_question q = iter.next();
System.out.println(q.toString());
}
}
I get the error:
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.
Dez 19, 2013 5:52:40 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.4.sp1
Dez 19, 2013 5:52:40 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Dez 19, 2013 5:52:40 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Dez 19, 2013 5:52:40 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Dez 19, 2013 5:52:41 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Dez 19, 2013 5:52:41 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Dez 19, 2013 5:52:41 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Dez 19, 2013 5:52:41 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost:5432/ecm_politik_mt
Dez 19, 2013 5:52:41 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=ecm, password=****}
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: PostgreSQL, version: 9.3.2
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 9.3 JDBC4.1 (build 1100)
Dez 19, 2013 5:52:41 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.PostgreSQLDialect
Dez 19, 2013 5:52:41 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
Dez 19, 2013 5:52:41 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)
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Dez 19, 2013 5:52:41 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.EhCacheProvider
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Dez 19, 2013 5:52:41 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Dez 19, 2013 5:52:41 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Dez 19, 2013 5:52:42 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Dez 19, 2013 5:52:42 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 0, SQLState: 42703
Dez 19, 2013 5:52:42 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ERROR: Column survey_que0_.id does not exist
Position: 8
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2223)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.database.SurveyMain.showEntries(SurveyMain.java:23)
at com.database.SurveyMain.main(SurveyMain.java:14)
Caused by: org.postgresql.util.PSQLException: ERROR: Column survey_que0_.id does not exist
Position: 8
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:560)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
... 9 more
I don't get why it's searching for "survey_que0_.id".
This usually happens,if you don't have corresponding column 'id' in Database table.
Related
This is the application to transfer money from one to another account by using spring and I got the error "injection of autowired dependencies failed". I got executed with the MySQL but not with Oracle and I thought this might be an issue of the Oracle version and I tried executing on the different version of Oracle but the error was the same.
Nov 07, 2017 1:24:10 PM org.springframework.test.context.support.AbstractTestContextBootstrapper getDefaultTestExecutionListenerClassNames
INFO: Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
Nov 07, 2017 1:24:10 PM org.springframework.test.context.support.AbstractTestContextBootstrapper instantiateListeners
INFO: Could not instantiate TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [javax/servlet/ServletContext]
Nov 07, 2017 1:24:10 PM org.springframework.test.context.support.AbstractTestContextBootstrapper getTestExecutionListeners
INFO: Using TestExecutionListeners: [org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener#1fd17e3, org.springframework.test.context.support.DependencyInjectionTestExecutionListener#dbc5d3, org.springframework.test.context.support.DirtiesContextTestExecutionListener#a9e816, org.springframework.test.context.transaction.TransactionalTestExecutionListener#1d99928, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener#34d63f]
Nov 07, 2017 1:24:10 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [config.xml]
Nov 07, 2017 1:24:11 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.GenericApplicationContext#1829d67: startup date [Tue Nov 07 13:24:11 CST 2017]; root of context hierarchy
Nov 07, 2017 1:24:12 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.5.6-Final
Nov 07, 2017 1:24:12 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Nov 07, 2017 1:24:12 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : javassist
Nov 07, 2017 1:24:12 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Nov 07, 2017 1:24:12 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: pojos.Withdraw -> WITHDRAW
Nov 07, 2017 1:24:12 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: pojos.Depostie -> DEPOSITE
Nov 07, 2017 1:24:12 PM org.springframework.orm.hibernate3.LocalSessionFactoryBean buildSessionFactory
INFO: Building new Hibernate SessionFactory
Nov 07, 2017 1:24:12 PM org.hibernate.connection.ConnectionProviderFactory initializeConnectionProviderFromConfig
INFO: Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Oracle, version: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Oracle JDBC driver, version: 11.1.0.7.0-Production
Nov 07, 2017 1:24:15 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.Oracle10gDialect
Nov 07, 2017 1:24:15 PM org.hibernate.engine.jdbc.JdbcSupportLoader useContextualLobCreation
INFO: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
Nov 07, 2017 1:24:15 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
Nov 07, 2017 1:24:15 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)
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: enabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Nov 07, 2017 1:24:15 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory createRegionFactory
INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Check Nullability in Core (should be disabled when Bean Validation is on): enabled
Nov 07, 2017 1:24:15 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: pojos.Withdraw -> WITHDRAW
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: pojos.Depostie -> DEPOSITE
Nov 07, 2017 1:24:15 PM org.springframework.orm.hibernate3.LocalSessionFactoryBean buildSessionFactory
INFO: Building new Hibernate SessionFactory
Nov 07, 2017 1:24:15 PM org.hibernate.connection.ConnectionProviderFactory initializeConnectionProviderFromConfig
INFO: Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Oracle, version: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Oracle JDBC driver, version: 11.1.0.7.0-Production
Nov 07, 2017 1:24:15 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.Oracle10gDialect
Nov 07, 2017 1:24:15 PM org.hibernate.engine.jdbc.JdbcSupportLoader useContextualLobCreation
INFO: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
Nov 07, 2017 1:24:15 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
Nov 07, 2017 1:24:15 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)
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: enabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Nov 07, 2017 1:24:15 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory createRegionFactory
INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Nov 07, 2017 1:24:15 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Check Nullability in Core (should be disabled when Bean Validation is on): enabled
Nov 07, 2017 1:24:15 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Nov 07, 2017 1:24:15 PM org.springframework.context.support.AbstractApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transferMoney': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.transaction.support.TransactionTemplate tx.TransferMoney.txTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.support.TransactionTemplate#0' defined in class path resource [config.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'transactionManager' is required
Nov 07, 2017 1:24:15 PM org.springframework.test.context.TestContextManager prepareTestInstance
SEVERE: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener#dbc5d3] to prepare test instance [test.TxTest#1d6ca49]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:230)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:249)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transferMoney': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.transaction.support.TransactionTemplate tx.TransferMoney.txTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.support.TransactionTemplate#0' defined in class path resource [config.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'transactionManager' is required
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
... 25 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.transaction.support.TransactionTemplate tx.TransferMoney.txTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.support.TransactionTemplate#0' defined in class path resource [config.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'transactionManager' is required
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 41 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.support.TransactionTemplate#0' defined in class path resource [config.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'transactionManager' is required
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
... 43 more
Caused by: java.lang.IllegalArgumentException: Property 'transactionManager' is required
at org.springframework.transaction.support.TransactionTemplate.afterPropertiesSet(TransactionTemplate.java:119)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 53 more
And here is the configuration file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<context:component-scan base-package="tx daoimpl" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:#localhost:1521:xe" />
<property name="username" value="system" />
<property name="password" value="system" />
<property name="initialSize" value="5" />
<property name="maxActive" value="10" />
</bean>
<!-- Mixing autowiring with explicit wiring -->
<bean class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
autowire="byName">
<!-- <property name="dataSource" ref="dataSource" /> -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</prop>
</props>
</property>
<property name="mappingResources">
<array>
<value>withdraw.hbm.xml</value>
<value>deposit.hbm.xml</value>
</array>
</property>
</bean>
<bean class="org.springframework.transaction.support.TransactionTemplate"
autowire="constructor" />
<bean class="org.springframework.orm.hibernate3.HibernateTransactionManager"
autowire="constructor" />
<bean class="org.springframework.orm.hibernate3.HibernateTemplate"
autowire="constructor" />
</beans>
And this is the Service code
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
import daoimpl.DepositImpl;
import daoimpl.WithdrawdaoImpl;
import pojos.Deposit;
import pojos.Withdraw;
#Service("transferMoney")
public class TransferMoney implements ITransfer{
#Autowired
private TransactionTemplate txTemplate;
#Autowired
private WithdrawdaoImpl withdrawdao;
#Autowired
private DepositImpl depositdao;
public void transfer(int fromAcc, int toAcc) {
txTemplate.execute(new TransactionCallback(){
public Object doInTransaction(TransactionStatus arg0){
try{
Withdraw w=withdrawdao.read(fromAcc);
w.setAmount(w.getAmount() - 100);
withdrawdao.update(w);
Deposit d=depositdao.read(toAcc);
d.setAmount(d.getAmount() + 100);
depositdao.update(d);
}catch(Exception e){
e.printStackTrace();
arg0.setRollbackOnly();
}
return null;
}
});
}
}
You can try two options. First add id="transactionManager" to your HibernateTransactionManager bean definition.
if that doesn't help than try following configuration:
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- Instance of transaction template -->
<bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="transactionManager"></property>
</bean>
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'm having a problem when configuring my first hibernate program, but I was stuck at the final step of the process.
Here is the stacktrace:
Dec 01, 2015 6:54:34 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.5.6-Final
Dec 01, 2015 6:54:34 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Dec 01, 2015 6:54:34 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : javassist
Dec 01, 2015 6:54:34 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Dec 01, 2015 6:54:34 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: hibernate.cfg.xml
Dec 01, 2015 6:54:34 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: hibernate.cfg.xml
Dec 01, 2015 6:54:34 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : edu/aspire/li/Student.hbm.xml
Dec 01, 2015 6:54:34 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: edu.aspire.li.Student -> STUDENT
Dec 01, 2015 6:54:34 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Dec 01, 2015 6:54:34 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Dec 01, 2015 6:54:34 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Dec 01, 2015 6:54:34 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Dec 01, 2015 6:54:34 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: oracle.jdbc.OracleDriver at URL: jdbc:oracle:thin:#localhost:1521:XE
Dec 01, 2015 6:54:34 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=system, password=****, autocommit=false}
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Oracle, version: Oracle Database 11g Release 11.1.0.0.0 - Production
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Oracle JDBC driver, version: 10.2.0.1.0XE
Dec 01, 2015 6:54:35 PM org.hibernate.dialect.resolver.StandardDialectResolver resolveDialectInternal
WARNING: Oracle 11g is not yet fully supported; using 10g dialect
Dec 01, 2015 6:54:35 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.Oracle10gDialect
Dec 01, 2015 6:54:35 PM org.hibernate.engine.jdbc.JdbcSupportLoader useContextualLobCreation
INFO: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
Dec 01, 2015 6:54:35 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
Dec 01, 2015 6:54:35 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 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: enabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Dec 01, 2015 6:54:35 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory createRegionFactory
INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Dec 01, 2015 6:54:35 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Check Nullability in Core (should be disabled when Bean Validation is on): enabled
Dec 01, 2015 6:54:35 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Exception in thread "main" org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:110)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:135)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:80)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:323)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:475)
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:297)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385)
at edu.aspire.daos.InsertStudent.main(InsertStudent.java:15)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:107)
... 9 more
Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for sname in class edu.aspire.li.Student
at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:328)
at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:321)
at org.hibernate.mapping.Property.getGetter(Property.java:304)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:299)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:158)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:77)
... 14 more
My mapping file(Student.hbm.xml):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="edu.aspire.li.Student" table="STUDENT">
<!-- id property -->
<id name="sno" column="SNO" type="integer" >
<!-- Primary key generator class -->
<generator class="assigned"/>
</id>
<!-- common properties -->
<property name ="sname" column="SNAME" type="string" length="100"/>
<property name ="email" column="EMAIL" type="string" length="100"/>
<property name ="mobile" column="MOBILE" type="long" not-null="true"/>
</class>
</hibernate-mapping>
my hibernate configuration file(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">oracle.jdbc.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:#localhost:1521:XE</property>
<property name="connection.username">system</property>
<property name="connection.password">root</property>
<!-- Disable autocommit mode -->
<property name="hibernate.connection.autocommit">false</property>
<!-- Print all generated SQL statements to the console -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>
<!-- Use JDBC transactions -->
<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory </property>
<!-- Mapping POJO to TABLE in underlying Database. -->
<mapping resource="edu/aspire/li/Student.hbm.xml" />
</session-factory>
</hibernate-configuration>
and my InsertStudent class:
package edu.aspire.daos;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import edu.aspire.li.Student;
//Insert Student object as student record into DataBase
class InsertStudent {
public static void main(String[] args) {
// TODO Auto-generated method stub
Configuration cfg = new Configuration();
cfg.configure("hibernate.cfg.xml");
SessionFactory sf = cfg.buildSessionFactory();
//Open Session
Session s = sf.openSession();
//Begin transaction
Transaction tx=s.beginTransaction();
//Create Student object
Student s1 = new Student();
s1.setSno(1);
s1.setName("abc");
s1.setEmail("abc#aspire.com");
s1.setMobile(7788198899L);
s.save(s1);
s.flush();
tx.commit();
s.close();
}
}
I put my student class, student.hbm.xml in edu.aspire.li, my insert student class in edu.aspire.daos, and my hibernate.cfg.xml in default package.
Thanks in advance.
I got this error when running Spring Boot 2.0.5 with JDK11. To fix it, I had to update the javassist library version (Gradle is my build tool):
compile('org.javassist:javassist:3.23.1-GA') {force = true}
For more info on migrating to JDK11, I found this blog post useful. Alternatively, upgrading to Spring Boot to 2.1 will fix this issue.
Do you run Spring Boot on the JDK 11?
I met the same question when I switched to JDK 11.
I resolved it by changing the Spring Boot version.
Thanks for # cpierceworld, I declare my student as
package edu.aspire.li;
import java.io.Serializable;
public class Student implements Serializable{
private int sno;
private String name;
private String email;
private long mobile;
public Student(){
System.out.println("This is to construct student");
}
public int getSno() {
return sno;
}
public void setSno(int sno) {
this.sno = sno;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public long getMobile() {
return mobile;
}
public void setMobile(long mobile) {
this.mobile = mobile;
}
}
There is a name conflict with student.hbm.xml
<property name ="sname" column="SNAME" type="string" length="100"/>
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.
When I access derby through netbeans and log the results everything I get good data,
but when I do the exact same thing through PHP-Java Bridge I get no data.
In package:
com.m1sk.HelloBridge
public static String backTest() throws Exception
{
BackendLink back = new BackendLink();
return back.GetTourists();
}
When called though the main I get something like this:
[{<Json Representation of the only object in the database>}]
This is good,
but When I call this function with PHP-Java Bridge
<?
$test = new Java("com.m1sk.HelloBridge");
echo "!!<br>";
echo $test->backTest();
?>
I get
!!
[]
Basically it calls the function but for some reason when it accesses the actual database it doesnt get the same thing!
Edit
*Backend_DAO_DB_impl:*
EntityManager em;
public Backend_DAO_DB_impl()
{
String PersistenceName = "XYZ;
EntityManagerFactory emf = Persistence.createEntityManagerFactory(PersistenceName);
em =emf.createEntityManager();
}
public ArrayList<Tourist> GetTourists()
{
Query q = em.createQuery("from Tourist");
return (ArrayList<Tourist>) q.getResultList();
}
BackendLink
public String GetTourists() throws Exception
{
ArrayList<Tourist> tourists = back.GetTourists();
JSONArray arr = new JSONArray();
for(Tourist t : tourists)
{
arr.add(JSONConverter.touristToJSON(t));
}
return arr.toJSONString();
}
back is an object of Backend_DAO_DB_impl
The BackendLink works at least when running in eclipse.
The problem isnt with the JSONConverter, I checked.
So It must be something deeper in the code, meaning its probably
something in derby or hibernate.
My current guess is that netbeans does something automatically that i'm not doing with the java bridge.
Edit
As requested here are the logs:
Catalina
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: java5772_5140_9448_modelDB.TouristSite
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity java5772_5140_9448_modelDB.TouristSite on table TouristSite
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: java5772_5140_9448_modelDB.InsideSites
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: java5772_5140_9448_modelDB.OutsideSites
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: java5772_5140_9448_modelDB.TourReservation
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity java5772_5140_9448_modelDB.TourReservation on table TourReservation
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: java5772_5140_9448_modelDB.Tourist
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity java5772_5140_9448_modelDB.Tourist on table Tourist
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.AnnotationConfiguration secondPassCompile
**INFO: Hibernate Validator not found: ignoring**
Jul 25, 2012 9:16:06 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Jul 25, 2012 9:16:06 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Jul 25, 2012 9:16:06 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: true
Jul 25, 2012 9:16:06 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.apache.derby.jdbc.ClientDriver at URL: jdbc:derby://localhost:1527/sample
Jul 25, 2012 9:16:06 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=app, password=****, autocommit=true, release_mode=auto}
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Apache Derby, version: 10.8.1.2 - (1095077)
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Apache Derby Network Client JDBC Driver, version: 10.2.2.1 - (538595)
Jul 25, 2012 9:16:06 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.DerbyDialect
Jul 25, 2012 9:16:06 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
Jul 25, 2012 9:16:06 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Jul 25, 2012 9:16:06 AM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: enabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Jul 25, 2012 9:16:06 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Jul 25, 2012 9:16:06 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Jul 25, 2012 9:16:06 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: Running hbm2ddl schema export
Jul 25, 2012 9:16:06 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: exporting generated schema to database
Jul 25, 2012 9:16:08 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: schema export complete
The other ones seem OK. Im not really sure about that line.