Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Hibernate Version 3.0
Mapping documents:
<?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="com.ibm.hibernate.Note" table="note">
<id name="noteId" column="note_id">
<generator class="assigned"></generator>
</id>
<property name="createDt" column="create_dt"></property>
<property name="crtdBy" column="crtd_by"></property>
<property name="effvDt" column="effv_dt"></property>
<property name="endDt" column="end_dt"></property>
<property name="note1" column="note_topic"></property>
<property name="updtdBy" column="updtd_by"></property>
<property name="updtDt" column="updt_dt"></property>
<!--property name="subrdtNoteId" column="subrdt_note_id"></property-->
<!-- child-->
<many-to-one name="note" class="com.ibm.hibernate.Note">
<column name="subrdt_note_id"></column>
</many-to-one>
<set name="noteassn">
<key column="note_id"></key>
<one-to-many class="com.ibm.hibernate.NoteAssn"/>
</set>
<set name="notes">
<key column="note_id"></key>
<one-to-many class="com.ibm.hibernate.Note"/>
</set>
</class>
</hibernate-mapping>
*************************************************************
The way i am testing my code is here:
package com.ibm.hibernatetest;
import java.util.Set;
import com.ibm.hibernate.Note;
import com.ibm.hibernatedao.NoteDAO;
public class NoteDAOTest {
public static void main(String args[])
{
NoteDAO dao = new NoteDAO();
Note note = dao.findById(new Long(1));
System.out.println(note.getNote1());
Note noteSub = new Note();
Long l1 = new Long(5);
noteSub.setCreateDt("11-MAY-07");
noteSub.setUpdtDt("09-JUN-07");
noteSub.setCrtdBy("NAVEEN");
noteSub.setUpdtdBy("NAVEEN");
noteSub.setEffvDt("10-JUN-05");
noteSub.setEndDt("10-JUN-09");
noteSub.setNoteId(l1);
noteSub.setNote1("EMPLOYER CASE DETAILS");
noteSub.setNote(note);
note.getNotes().add(noteSub);
System.out.println("Done");
dao.appendNote(note);
}
}
This should actually update the DataBase but there is nothing actually updated
Code between sessionFactory.openSession() and session.close():
public void appendNote(Object object)
{
log.debug("Appending Notes to Subordinate Note");
try
{
Transaction tx = getSession().beginTransaction();
getSession().saveOrUpdate(object);
tx.commit();
}
catch(RuntimeException re)
{
log.error("Append Failed",re);
throw re;
}
finally
{
getSession().flush();
System.out.println("Session Flushed");
getSession().close();
System.out.println("Session Closed");
}
}
Full stack trace of any exception that occurs:
14:28:18,031 INFO Environment:479 - Hibernate 3.1.3
14:28:18,046 INFO Environment:509 - hibernate.properties not found
14:28:18,046 INFO Environment:525 - using CGLIB reflection optimizer
14:28:18,046 INFO Environment:555 - using JDK 1.4 java.sql.Timestamp handling
14:28:18,140 INFO Configuration:1308 - configuring from resource: hibernate.cfg.xml
14:28:18,140 INFO Configuration:1285 - Configuration resource: hibernate.cfg.xml
14:28:18,468 INFO Configuration:469 - Reading mappings from resource: config/entity.hbm.xml
14:28:18,625 INFO HbmBinder:309 - Mapping class: com.ibm.hibernate.Entity -> entity
14:28:18,734 INFO Configuration:469 - Reading mappings from resource: config/entitytyp.hbm.xml
14:28:18,781 INFO HbmBinder:309 - Mapping class: com.ibm.hibernate.EntityTyp -> entity_typ
14:28:18,781 INFO Configuration:469 - Reading mappings from resource: config/entrprs.hbm.xml
14:28:18,828 INFO HbmBinder:309 - Mapping class: com.ibm.hibernate.EnterpriseNameType -> entrprs_nm_typ
14:28:18,843 INFO Configuration:469 - Reading mappings from resource: config/intdparty.hbm.xml
14:28:18,875 INFO HbmBinder:309 - Mapping class: com.ibm.hibernate.IntdPty -> intd_pty
14:28:18,906 INFO HbmBinder:883 - Mapping joined-subclass: com.ibm.hibernate.IndivEntity -> indiv_entity
14:28:18,906 INFO HbmBinder:883 - Mapping joined-subclass: com.ibm.hibernate.Worker -> indiv_entity
14:28:18,921 INFO HbmBinder:883 - Mapping joined-subclass: com.ibm.hibernate.BusnsEntity -> busns_entity
14:28:18,921 INFO HbmBinder:883 - Mapping joined-subclass: com.ibm.hibernate.Employer -> employer
14:28:18,921 INFO Configuration:469 - Reading mappings from resource: config/intdptyassn.hbm.xml
14:28:18,937 INFO HbmBinder:309 - Mapping class: com.ibm.hibernate.IntdPtyAssn -> intd_pty_assn
14:28:18,937 INFO Configuration:469 - Reading mappings from resource: config/intdptynm.xml
14:28:18,968 INFO HbmBinder:309 - Mapping class: com.ibm.hibernate.IntdPtyNm -> intd_pty_nm
14:28:18,968 INFO Configuration:469 - Reading mappings from resource: config/intdptyrole.hbm.xml
14:28:18,984 INFO HbmBinder:309 - Mapping class: com.ibm.hibernate.IntdPtyRole -> intd_pty_role
14:28:18,984 INFO Configuration:469 - Reading mappings from resource: config/intdptyrolecat.hbm.xml
14:28:19,000 INFO HbmBinder:309 - Mapping class: com.ibm.hibernate.IntdPtyRoleCat -> intd_pty_role_cat
14:28:19,000 INFO Configuration:469 - Reading mappings from resource: config/naics.hbm.xml
14:28:19,015 INFO HbmBinder:309 - Mapping class: com.ibm.hibernate.Naics -> naics
14:28:19,015 INFO Configuration:469 - Reading mappings from resource: config/ofcrownrship.hbm.xml
14:28:19,031 INFO HbmBinder:309 - Mapping class: com.ibm.hibernate.OfcrOwnrshp -> ofcr_ownrshp
14:28:19,031 INFO Configuration:469 - Reading mappings from resource: config/ofcrtitle.hbm.xml
14:28:19,046 INFO HbmBinder:309 - Mapping class: com.ibm.hibernate.OfcrTitle -> ofcr_title
14:28:19,046 INFO Configuration:469 - Reading mappings from resource: config/roletyp.hbm.xml
14:28:19,062 INFO HbmBinder:309 - Mapping class: com.ibm.hibernate.RoleTyp -> role_typ
14:28:19,062 INFO Configuration:469 - Reading mappings from resource: config/intdptytypassn.hbm.xml
14:28:19,078 INFO HbmBinder:309 - Mapping class: com.ibm.hibernate.IntdPtyTypAssn -> intd_pty_typ_assn
14:28:19,078 INFO Configuration:469 - Reading mappings from resource: config/note.hbm.xml
14:28:19,093 INFO HbmBinder:309 - Mapping class: com.ibm.hibernate.Note -> note
14:28:19,093 INFO Configuration:469 - Reading mappings from resource: config/noteassn.hbm.xml
14:28:19,109 INFO HbmBinder:309 - Mapping class: com.ibm.hibernate.NoteAssn -> note_assn
14:28:19,109 INFO Configuration:1419 - Configured SessionFactory: null
14:28:19,109 INFO HbmBinder:2349 - Mapping collection: com.ibm.hibernate.Entity.officer -> ofcr_title
14:28:19,109 INFO HbmBinder:2349 - Mapping collection: com.ibm.hibernate.EntityTyp.intdPtyRole -> intd_pty_role
14:28:19,109 INFO HbmBinder:2349 - Mapping collection: com.ibm.hibernate.EnterpriseNameType.intdptynm -> intd_pty_nm
14:28:19,109 INFO HbmBinder:2349 - Mapping collection: com.ibm.hibernate.IntdPty.entity -> entity
14:28:19,109 INFO HbmBinder:2349 - Mapping collection: com.ibm.hibernate.IntdPty.intdptytypassn -> intd_pty_typ_assn
14:28:19,109 INFO HbmBinder:2349 - Mapping collection: com.ibm.hibernate.IntdPty.notesassn -> note_assn
14:28:19,109 INFO HbmBinder:2349 - Mapping collection: com.ibm.hibernate.BusnsEntity.intdptynm -> intd_pty_nm
14:28:19,109 INFO HbmBinder:2349 - Mapping collection: com.ibm.hibernate.IntdPtyRoleCat.intdPtyRole -> intd_pty_role
14:28:19,109 INFO HbmBinder:2349 - Mapping collection: com.ibm.hibernate.RoleTyp.intdPtyRole -> intd_pty_role
14:28:19,125 INFO HbmBinder:2349 - Mapping collection: com.ibm.hibernate.Note.noteassn -> note_assn
14:28:19,125 INFO HbmBinder:2349 - Mapping collection: com.ibm.hibernate.Note.notes -> note
14:28:19,296 WARN RootClass:210 - composite-id class does not override equals(): com.ibm.hibernate.OfcrOwnershipId
14:28:19,296 WARN RootClass:215 - composite-id class does not override hashCode(): com.ibm.hibernate.OfcrOwnershipId
14:28:19,312 WARN RootClass:210 - composite-id class does not override equals(): com.ibm.hibernate.OfcrTitleId
14:28:19,312 WARN RootClass:215 - composite-id class does not override hashCode(): com.ibm.hibernate.OfcrTitleId
14:28:19,328 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
14:28:19,328 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
14:28:19,328 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
14:28:19,343 INFO DriverManagerConnectionProvider:80 - using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@Naveen:1521:XE
14:28:19,343 INFO DriverManagerConnectionProvider:86 - connection properties: {user=naveen, password=****}
14:28:19,687 INFO SettingsFactory:77 - RDBMS: Oracle, version: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
14:28:19,687 INFO SettingsFactory:78 - JDBC driver: Oracle JDBC driver, version: 10.1.0.4.2
14:28:19,703 INFO Dialect:103 - Using dialect: org.hibernate.dialect.Oracle9Dialect
14:28:19,703 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
14:28:19,718 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
14:28:19,718 INFO SettingsFactory:125 - Automatic flush during beforeCompletion(): disabled
14:28:19,718 INFO SettingsFactory:129 - Automatic session close at end of transaction: disabled
14:28:19,718 INFO SettingsFactory:136 - JDBC batch size: 15
14:28:19,718 INFO SettingsFactory:139 - JDBC batch updates for versioned data: disabled
14:28:19,718 INFO SettingsFactory:144 - Scrollable result sets: enabled
14:28:19,718 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): disabled
14:28:19,718 INFO SettingsFactory:160 - Connection release mode: auto
14:28:19,718 INFO SettingsFactory:187 - Default batch fetch size: 1
14:28:19,718 INFO SettingsFactory:191 - Generate SQL with comments: disabled
14:28:19,718 INFO SettingsFactory:195 - Order SQL updates by primary key: disabled
14:28:19,718 INFO SettingsFactory:338 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
14:28:19,718 INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
14:28:19,718 INFO SettingsFactory:203 - Query language substitutions: {}
14:28:19,718 INFO SettingsFactory:209 - Second-level cache: enabled
14:28:19,718 INFO SettingsFactory:213 - Query cache: disabled
14:28:19,718 INFO SettingsFactory:325 - Cache provider: org.hibernate.cache.EhCacheProvider
14:28:19,718 INFO SettingsFactory:228 - Optimize cache for minimal puts: disabled
14:28:19,718 INFO SettingsFactory:237 - Structured second-level cache entries: disabled
14:28:19,734 INFO SettingsFactory:257 - Echoing all SQL to stdout
14:28:19,734 INFO SettingsFactory:264 - Statistics: disabled
14:28:19,734 INFO SettingsFactory:268 - Deleted entity synthetic identifier rollback: disabled
14:28:19,734 INFO SettingsFactory:283 - Default entity-mode: pojo
14:28:19,765 INFO SessionFactoryImpl:154 - building session factory
14:28:19,765 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Program%20Files/MyEclipse%205.1.1%20GA/eclipse/plugins/com.genuitec.org.hibernate.eclipse_5.1.1/myeclipse-data/3.0/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
14:28:20,421 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
Hibernate: select note0_.note_id as note1_16_0_, note0_.create_dt as create2_16_0_, note0_.crtd_by as crtd3_16_0_, note0_.effv_dt as effv4_16_0_, note0_.end_dt as end5_16_0_, note0_.note_topic as note6_16_0_, note0_.updtd_by as updtd7_16_0_, note0_.updt_dt as updt8_16_0_, note0_.subrdt_note_id as subrdt9_16_0_ from note note0_ where note0_.note_id=?
CLAIM INFO
Hibernate: select notes0_.note_id as note1_1_, notes0_.note_id as note1_16_0_, notes0_.create_dt as create2_16_0_, notes0_.crtd_by as crtd3_16_0_, notes0_.effv_dt as effv4_16_0_, notes0_.end_dt as end5_16_0_, notes0_.note_topic as note6_16_0_, notes0_.updtd_by as updtd7_16_0_, notes0_.updt_dt as updt8_16_0_, notes0_.subrdt_note_id as subrdt9_16_0_ from note notes0_ where notes0_.note_id=?
Done
Hibernate: update note set note_id=? where note_id=?
Session Flushed
Session Closed
Name and version of the database you are using:
Oracle 10G
The generated SQL (show_sql=true):
Hibernate: select note0_.note_id as note1_16_0_, note0_.create_dt as create2_16_0_, note0_.crtd_by as crtd3_16_0_, note0_.effv_dt as effv4_16_0_, note0_.end_dt as end5_16_0_, note0_.note_topic as note6_16_0_, note0_.updtd_by as updtd7_16_0_, note0_.updt_dt as updt8_16_0_, note0_.subrdt_note_id as subrdt9_16_0_ from note note0_ where note0_.note_id=?
CLAIM INFO
Hibernate: select notes0_.note_id as note1_1_, notes0_.note_id as note1_16_0_, notes0_.create_dt as create2_16_0_, notes0_.crtd_by as crtd3_16_0_, notes0_.effv_dt as effv4_16_0_, notes0_.end_dt as end5_16_0_, notes0_.note_topic as note6_16_0_, notes0_.updtd_by as updtd7_16_0_, notes0_.updt_dt as updt8_16_0_, notes0_.subrdt_note_id as subrdt9_16_0_ from note notes0_ where notes0_.note_id=?
Done
Hibernate: update note set note_id=? where note_id=?
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html