Hello Everybody,
I am trying a simple Hibernate program.The programs and stck trace are as follows,
Could you pl. look into it.
Hibernate.cfg.xml
Code:
<!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.Oracle10gDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">system</property>
<property name="hibernate.connection.password">qwerty1uiop</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
<property name="hibernate.hbm22ddl.auto">update</property>
<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
<property name="show_sql">true</property>
<property name="org.hibernate">debug</property>
<property name="use_sql_comments">true</property>
<mapping resource="com/wipro/Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Person.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.wipro">
<class name="Person" table="PERSON">
<id name="id" column="Person_ID" type="int">
<generator class="native"/>
</id>
<property name="firstName" />
<property name="lastName" />
</class>
</hibernate-mapping>
Code:
package com.wipro;
public class Person {
//every attribute should begin with small letter
//this is called a pojo in Hibernate.Only properties,stters an getters
private Integer id;
private String firstName;
private String lastName;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
Code:
package com.wipro;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
public class Manager1 {
public static void main(String[] args) {
Person p1=new Person();
p1.setId(101);
p1.setFirstName("suresh");
p1.setLastName("sankar");
Configuration c1=new Configuration();
c1.configure();
ServiceRegistry sr=new ServiceRegistryBuilder().applySettings(c1.getProperties()).buildServiceRegistry();
SessionFactory sf=c1.buildSessionFactory(sr);
Session s1=sf.openSession();
s1.beginTransaction();
s1.save(p1);
//s1.getTransaction().commit();
s1.getTransaction().commit();
s1.flush();
s1.close();
System.out.println("done");
}
}
Hibernate.properties
Code:
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\mkapp.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%c] - %m%n
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
# Root logger option
log4j.rootLogger=INFO, file, stdout
# Log everything. Good for troubleshooting
log4j.logger.org.hibernate=INFO
# Log all JDBC parameters
log4j.logger.org.hibernate.type=ALL
log4j.logger.org.hibernate.SQL=debug
Code:
Nov 30, 2016 4:47:19 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000422: Disabling contextual LOB creation as connection was null
Nov 30, 2016 4:47:19 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Nov 30, 2016 4:47:19 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Hibernate: /* insert com.wipro.Person */ insert into PERSON (firstName, lastName, Person_ID) values (?, ?, ?)
Nov 30, 2016 4:47:20 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 942, SQLState: 42000
Nov 30, 2016 4:47:20 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ORA-00942: table or view does not exist
Nov 30, 2016 4:47:20 PM org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release
INFO: HHH000010: On release of batch it still contained JDBC statements
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute statement
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)