Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Object Relational Mapping
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Liutauras Vilda
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Object Relational Mapping
Newbie got stuck in Hibernate "Hello World"
Tirthankar Mukherjee
Ranch Hand
Posts: 51
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Dept.java
package hello; public class Dept { String dept_id; String dept_name; String dept_job; public String getDept_id() { return dept_id; } public void setDept_id(String dept_id) { this.dept_id = dept_id; } public String getDept_name() { return dept_name; } public void setDept_name(String dept_name) { this.dept_name = dept_name; } public String getDept_job() { return dept_job; } public void setDept_job(String dept_job) { this.dept_job = dept_job; } }
FirstExample.java
package hello; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; public class FirstExample { public static void main(String[] args) { Session session = null ; try { SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); //SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); session = sessionFactory.openSession(); System.out.println("Inserting Record"); Dept dept = new Dept(); dept.setDept_id("5"); dept.setDept_name("Accounts"); dept.setDept_job("Taking care of all accounts"); session.save(dept); System.out.println("Done"); } catch (Exception e) { System.out.println("Error"); System.out.println(e.getMessage()); } finally { // Actual contact insertion will happen at this step session.flush(); session.close(); } } }
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="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <property name="hibernate.connection.password">tiger</property> <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:xe</property> <property name="hibernate.connection.username">scott</property> <property name="hibernate.default_schema">scott</property> <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property> <property name="show_sql">true</property> <property name="format_sql">true</property> <mapping resource="hello/Dept.hbm.xml"/> </session-factory> </hibernate-configuration>
Dept.hbm.xml
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="hello"> <class name="hello.Dept" table="dept"> <id name="dept_id" type="string" column="dept_id"> <generator class="assigned" /> </id> <property name="dept_name"> <column name="dept_name" /> </property> <property name="dept_job"> <column name="dept_job" /> </property> </class> </hibernate-mapping>
Eclipse console output
Jan 28, 2010 4:54:00 PM org.hibernate.cfg.Environment <clinit> INFO: Hibernate 3.2.5 Jan 28, 2010 4:54:00 PM org.hibernate.cfg.Environment <clinit> INFO: hibernate.properties not found Jan 28, 2010 4:54:00 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: Bytecode provider name : cglib Jan 28, 2010 4:54:00 PM org.hibernate.cfg.Environment <clinit> INFO: using JDK 1.4 java.sql.Timestamp handling Jan 28, 2010 4:54:00 PM org.hibernate.cfg.Configuration configure INFO: configuring from resource: /hibernate.cfg.xml Jan 28, 2010 4:54:00 PM org.hibernate.cfg.Configuration getConfigurationInputStream INFO: Configuration resource: /hibernate.cfg.xml Jan 28, 2010 4:54:00 PM org.hibernate.cfg.Configuration addResource INFO: Reading mappings from resource : hello/Dept.hbm.xml Jan 28, 2010 4:54:00 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues INFO: Mapping class: hello.Dept -> dept Jan 28, 2010 4:54:00 PM org.hibernate.cfg.Configuration doConfigure INFO: Configured SessionFactory: null Jan 28, 2010 4:54:00 PM org.hibernate.connection.DriverManagerConnectionProvider configure INFO: Using Hibernate built-in connection pool (not for production use!) Jan 28, 2010 4:54:00 PM org.hibernate.connection.DriverManagerConnectionProvider configure INFO: Hibernate connection pool size: 20 Jan 28, 2010 4:54:00 PM org.hibernate.connection.DriverManagerConnectionProvider configure INFO: autocommit mode: false Jan 28, 2010 4:54:00 PM org.hibernate.connection.DriverManagerConnectionProvider configure INFO: using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@localhost:1521:xe Jan 28, 2010 4:54:00 PM org.hibernate.connection.DriverManagerConnectionProvider configure INFO: connection properties: {user=scott, password=****} Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: RDBMS: Oracle, version: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: JDBC driver: Oracle JDBC driver, version: 10.2.0.1.0XE Jan 28, 2010 4:54:00 PM org.hibernate.dialect.Dialect <init> INFO: Using dialect: org.hibernate.dialect.Oracle10gDialect Jan 28, 2010 4:54:00 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory INFO: Using default transaction strategy (direct JDBC transactions) Jan 28, 2010 4:54:00 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) Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Automatic flush during beforeCompletion(): disabled Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Automatic session close at end of transaction: disabled Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: JDBC batch size: 15 Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: JDBC batch updates for versioned data: disabled Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Scrollable result sets: enabled Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: JDBC3 getGeneratedKeys(): disabled Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Connection release mode: auto Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Default schema: scott Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Default batch fetch size: 1 Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Generate SQL with comments: disabled Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Order SQL updates by primary key: disabled Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Order SQL inserts for batching: disabled Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory Jan 28, 2010 4:54:00 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init> INFO: Using ASTQueryTranslatorFactory Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Query language substitutions: {} Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: JPA-QL strict compliance: disabled Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Second-level cache: enabled Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Query cache: disabled Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory createCacheProvider INFO: Cache provider: org.hibernate.cache.NoCacheProvider Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Optimize cache for minimal puts: disabled Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Structured second-level cache entries: disabled Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Echoing all SQL to stdout Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Statistics: disabled Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Deleted entity synthetic identifier rollback: disabled Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Default entity-mode: pojo Jan 28, 2010 4:54:00 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Named query checking : enabled Jan 28, 2010 4:54:00 PM org.hibernate.impl.SessionFactoryImpl <init> INFO: building session factory Exception in thread "main" java.lang.NullPointerException at hello.FirstExample.main(FirstExample.java:28)
Detp table
create table dept( dept_id varchar2(20) primary key, dept_name varchar2(20) not null unique, dept_job varchar2(20) );
I cant get this code working. Please Help. Thanks in Advance
Tirthankar Mukherjee
Ranch Hand
Posts: 51
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
nway solved it ...
replaced cglib-2.2.jar with cglib-2.1.3.jar and it worked ...
If any one knows why .. please let me know ...
Forget this weirdo. You guys wanna see something really neat? I just have to take off my shoe .... (hint: it's a tiny ad)
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
SQLGrammarException
How to query?
problem with showing records in hibernate
SEVERE: Duplicate entry '1' for key 'PRIMARY'
Not able to update or save a object to database. please help.
More...